0Day Forums
How to run a command from a batch file and immediately return? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: .bat & .wsf & .cmd (https://0day.red/Forum-bat-wsf-cmd)
+--- Thread: How to run a command from a batch file and immediately return? (/Thread-How-to-run-a-command-from-a-batch-file-and-immediately-return)



How to run a command from a batch file and immediately return? - Sirrylanjfnzfw - 07-23-2023

When I am on the command line and do this:

"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" /command:log

a GUI dialog of [TortoiseGit][1] is opened and cmd.exe immediately returns, meaning that I can immediately run other commands like `dir` etc.

Because the aforementioned command is quite long, I created a helper batch file, tgit.cmd, that contains just this:

@echo off
"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" /command:%1 %*

I can now call just **tgit log** which is great, however, there is one difference: the command-line is blocked until I close the TortoiseGit dialog.

I have also tried

cmd /C "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" /command:%1 %*

but that doesn't make any difference. How to immediately return from the batch file?

[1]:

[To see links please register here]




RE: How to run a command from a batch file and immediately return? - sydneyite56337 - 07-23-2023

Use START to run the command.

start "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" "/command:log"


RE: How to run a command from a batch file and immediately return? - horrocks429 - 07-23-2023

The answer from Oscar is almost correct, but needs a correction

start "" "C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" /command:%1 %*

Why?

`start` command has a curious behaviour: the first quoted argument is used to determine the title of a new `cmd` window, and no, it doesn't matter that no `cmd` window will be started. First quoted argument is the title.

That is the reason for the empty double quotes in the previous code. Without it, what the `start` command sees is

start "title=c:\Progra..." /command:....

and as the `start` command does not include a `/command` switch, it fails.