下一頁評論批處理腳本顯示了可能的方法來運行明顯
- 另一個批處理腳本:
cliParser.bat
僅僅列出所有提供的參數;
cliParseArg.bat
做同樣和集errorlevel
到參數計數由exit /b %i%
(從零開始所以從來returs 0
);
- a GUI應用程序:行使普通
calc
和notepad
可執行文件;
- 一個Win32控制檯應用程序:
cliParser.exe
是cliParser.bat
改寫爲C++
;
從一個不可見的命令行窗口中。給出瞭如何以異步方式以及同步方式運行的示例(即等待被調用的應用程序結束)。
@ECHO OFF
SETLOCAL EnableExtensions
rem STDOUT output is invisible if this script runs in a hidden window
wmic OS get LocalDateTime
rem another batch script asynchronously => visible
start "batch asyn" cmd /K ""D:\bat\cliParser.bat" par1 %* "par 3""
rem errorlevel clear: by virtue of Dave Benham in reply to http://superuser.com/a/649329/376602
(call)
rem another batch script synchronously => visible
start "batch synchr" /WAIT cmd /K "("D:\bat\cliParseArg.bat" par1 %* "par 3"&pause&exit /B %%%%errorlevel%%%%)"
rem `pause` command in above line is merely for debugging purposes to ensure that window is visible
echo cliParseArg.bat parameter count=%errorlevel%
echo(
rem a GUI application asynchronously => visible
start "" calc.exe
rem a GUI application synchronously => visible
notepad.exe
rem a console application asynchronously => visible
start "CApp asyn" cmd /K ""D:\bat\cliParser.exe" rap1 %* "rap 3""
rem a console application synchronously => visible
start "CApp synchr" /WAIT cmd /K "("D:\bat\cliParser.exe" arg1 %* "arg 3"&exit /B)"
rem STDOUT output is invisible if this script runs in a hidden window
cmd /C wmic OS get LocalDateTime
輸出如果從可見cmd
窗口稱爲第一,然後在隱藏的窗口::
==> D:\bat\SO\37181230.bat "xx yy"
LocalDateTime
20160512195221.499000+120
cliParseArg.bat parameter count=4
LocalDateTime
20160512195244.958000+120
==> Wscript D:\VB_scripts\runhidden.vbs "D:\bat\SO\37181230.bat" "A1 B2"
==>
的runhidden.vbs
從Rob van der Woude's script適於其中
strArguments = strArguments & " " & WScript.Arguments(i)
線變爲
strArguments = strArguments & " """ & WScript.Arguments(i) & """"
你可以添加你在批處理文件中使用的代碼來啓動程序到你的問題嗎? –
例如'helloworld.exe par1 par2' 我們使用的場景是啓動批處理,讓它進行一些檢查,然後讓它使用一些輸入參數啓動應用程序helloworld.exe。 – andreasgk
你可以試試'開始cmd/k「helloworld.exe par1 par2」' –