简体   繁体   English

如何使用批处理文件在一个文件中执行多个命令?

[英]How to execute several command in one file with a batch file?

I am actually writing a little PHP script, in order to retrieve files in folder on a FTP server and download them locally. 我实际上正在编写一个小的PHP脚本,以便在FTP服务器上的文件夹中检索文件并在本地下载它们。 Another script put those file in the server. 另一个脚本将这些文件放入服务器。

So here's my question : how can I write a batch file that will execute the first php script, then run a program (a game in this case). 所以这是我的问题:如何编写一个批处理文件,它将执行第一个php脚本,然后运行一个程序(在本例中为游戏)。 When the game is closed, execute the second script. 游戏关闭时,执行第二个脚本。

So it will be this process : 因此将是这个过程:

  1. When run the batch file, execute the first script (get file) 运行批处理文件时,执行第一个脚本(获取文件)
  2. When all files are downloaded, run the programm ( game.exe ) 下载所有文件后,运行程序( game.exe
  3. After game closing, execute the second script (put file) 游戏结束后,执行第二个脚本(put文件)

I think at a .bat file, but maybe there is an another solution. 我认为在.bat文件中,但也许还有另一种解决方案。

Thanks is advance ! 谢谢是前进! Telest. Telest。



EDIT : Thanks for your answer. 编辑:感谢您的回答。

Google gives me this post : How to wait for a process to terminate to execute another process in batch file . Google给我这篇文章: 如何等待进程终止以执行批处理文件中的另一个进程 I found that I can use /W in order to wait the program ends. 我发现可以使用/W来等待程序结束。

But /W seems not working. 但是/W似乎不起作用。 Tried /WAIT but no success. 尝试/WAIT但未成功。

Here is my batch file : 这是我的批处理文件:

PHP C:\Users\PHProjects\test1.php
START /WAIT /B chrome.exe
PHP C:\Users\PHProjects\test2.php
PAUSE

(test1.php & test2.php are just dummy echo). (test1.php和test2.php只是虚拟回声)。

And the console result : 和控制台结果:

Chrome executes well, but test2 too Chrome执行良好,但也test2

As you can see, Chrome executes well, but so do test2.php. 如您所见,Chrome执行得很好,但test2.php也是如此。

Is something wrong here ? 这有什么问题吗?

Thanks. 谢谢。

call getfile.bat
start "" /w game.exe
call putfile.bat

see start /? 看到start /? and call /?. 并致电/?。 With start take note of the second half which details how not using start works (confusing I know}. Call details, as start details for programs, how it works calling a batch directly versus call . 使用start请注意后半部分,其中详细说明了不使用start的方式(我知道这令人困惑)。 Call详细信息(作为程序的start详细信息)是如何直接调用批处理而不是call

我用新元素更新了我的第一篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM