Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a command from a batch file and immediately return?

When I am on the command line and do this:

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

a GUI dialog of TortoiseGit 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?

like image 711
Borek Bernard Avatar asked Feb 11 '23 01:02

Borek Bernard


1 Answers

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.

like image 170
MC ND Avatar answered Mar 04 '23 03:03

MC ND