在.vbs中我有类似
的东西 Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
'run conf
sh.run "cmd /K php -c php.ini -f some_path\runer\run.php & pause",0,false
'Navigate to the nginx folder to run server
sh.run "cmd /K start nginx & exit", 0, false
Set sh = Nothing
此代码工作正常。
但我希望在完成sh.run "cmd /K start nginx & exit", 0, false
此命令的执行后执行sh.run "cmd /K php -c php.ini -f some_path\runer\run.php & pause",0,false
,这意味着,在完成run.php
的任务后,我想要run nginx
。如果有可能请回答我。感谢
答案 0 :(得分:4)
使用此,
Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
'run conf
sh.run "cmd /K php -c php.ini -f some_path\runer\run.php & exit",1,true
'Navigate to the nginx folder to run server
sh.run "cmd /K start nginx & exit", 0, false
Set sh = Nothing
答案 1 :(得分:1)
这是您方法的文档。你告诉它不要等。有些原因你没有想过阅读文档吗?
在新流程中运行程序。
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
参数 宾语 WshShell对象。
strCommand 字符串值,指示要运行的命令行。您必须包含要传递给可执行文件的任何参数。
intWindowStyle 可选的。整数值,表示程序窗口的外观。请注意,并非所有程序都使用此信息。
bWaitOnReturn 可选的。布尔值,指示脚本是否应该等待程序完成执行,然后再继续执行脚本中的下一个语句。如果设置为true,则脚本执行将暂停,直到程序完成,Run将返回程序返回的任何错误代码。如果设置为false(默认值),Run方法在启动程序后立即返回,自动返回0(不被解释为错误代码)。
备注 Run方法返回一个整数。 Run方法启动在新Windows进程中运行的程序。您可以让脚本等待程序完成执行,然后再继续。这允许您同步运行脚本和程序。参数strCommand中的环境变量会自动扩展。如果文件类型已正确注册到特定程序,则在该类型的文件上调用run将执行该程序。例如,如果您的计算机系统上安装了Word,则在* .doc文件上调用Run将启动Word并加载该文档。下表列出了intWindowStyle的可用设置。
intWindowStyle Description
0
Hides the window and activates another window.
1
Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2
Activates the window and displays it as a minimized window.
3
Activates the window and displays it as a maximized window.
4
Displays a window in its most recent size and position. The active window remains active.
5
Activates the window and displays it in its current size and position.
6
Minimizes the specified window and activates the next top-level window in the Z order.
7
Displays the window as a minimized window. The active window remains active.
8
Displays the window in its current state. The active window remains active.
9
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10
Sets the show-state based on the state of the program that started the application.
示例1 以下VBScript代码使用记事本打开当前运行脚本的副本。
复制代码
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName
以下VBScript代码执行相同的操作,除了它指定窗口类型,等待用户关闭记事本,并保存记事本关闭时返回的错误代码。
复制代码
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
示例2 以下VBScript代码打开命令窗口,更改为C:\的路径,并执行DIR命令。
复制代码
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing
适用于:
答案 2 :(得分:1)
试试这个
sh.run "cmd /K php -c php.ini -f some_path\runer\run.php & exit",1,true
答案 3 :(得分:1)
对于您可以使用的任何查询:
Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
sh.run "cmd /K a.exe & exit",1,true
Set sh = Nothing
我认为这会对你有帮助。