在 C++ 中,如何在第一个结束后才执行第二个“system()"? [英] In C ++, how to execute the second 'system()' only after the first one is over?
问题描述
请看下面的代码.如果有任何替代系统可以满足我的要求,那也很好.
See the code below. If there is any alternative to system that does what I want it would be good too.
strcat(comando1,"start c:\\arquiv~1\\winrar\\rar a D:\\sisbibbkp\\teste1");
strcat(comando1,data);
strcat(comando1,".rar E:\\softwares");
system(comando1);
strcat(comando2,"start c:\\arquiv~1\\winrar\\rar a D:\\sisbibbkp\\teste2");
strcat(comando2,data);
strcat(comando2,".rar E:\\softwares");
system(comando2); // I want this system to run only after system (command1) finishes.
推荐答案
start
命令将事物作为单独的作业运行:
The start
command runs things as a separate job:
C:\Users\Pax> start /?
Starts a separate window to run a specified program or command.
如果您想等待它完成,只需从命令中删除 start
.
If you want to wait for it to finish, just remove the start
from the command.
或者,如果您希望整个 thing 单独运行但让第 2 步等待第 1 步完成,请将两者都放入 cmd
脚本(不带 start
bits) 和 start cmd.exe
在您的脚本上执行此操作.
Or if you want the whole thing to run separately but have step 2 wait for step 1 to finish, put both into a cmd
script (without the start
bits) and start cmd.exe
on your script to do it.
这应该启动一个单独的作业来运行脚本,但该作业将按顺序运行脚本中的命令.
That should start a separate job to run the script but that job will run the command in the script sequentially.
这篇关于在 C++ 中,如何在第一个结束后才执行第二个“system()"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!