I have a batch file that I usually invoke like this:
longjob.cmd >result.txt 2>&1
This works fine, but the script changes directory during its execution leaving my shell in that directory - which is a nuisance.
Is there a way to run the command within a sub-shell - while still allowing the output to be captured ?
I have tried
cmd longjob.cmd >result.txt 2>&1
which just sits waiting for an exit command.
Also I tried
start longjob.cmd >result.txt 2>&1
which does run the script, but in a new window and all output is sent to that window instead of the file.
Batch files can be run by typing "start FILENAME. bat". Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal. When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.
To start an exe file from a batch file in Windows, you can use the start command. For example, the following command would start Notepad in most versions of Windows. The start command can be used for other exe files by replacing the file path with the path to the exe file.
Windows Command Prompt (also known as the command line, cmd.exe or simply cmd) is a command shell based on the MS-DOS operating system from the 1980s that enables a user to interact directly with the operating system.
Try
CMD /C longjob.cmd >result.txt 2>&1
Not sure how it'll deal with the redirection, but CMD /C lets you tell CMD what to run and that it should exit when done. (CMD /K lets you tell it to run something but stick around when done.) It will re-use the existing console window if run within one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With