目标过程:QProcess启动系统的cmd.exe,cmd.exe再去启动另一个 A.exe。
注意知识点:
-
QProcess.setProgram("cmd.exe");方式启动cmd.exe, 此时给的参数意义:\c xx xx 表示告诉cmd.exe此时不用等待键盘输入,直接以xx xx作为命令行参数了。\c 的作用就是告诉cmd.exe不用等待键盘输入。具体需要看windows关于cmd的手册了。 如果参数直接给了A.exe,是运行不了A.exe的,因为A.exe不是一个解释选项。而在Linux系统中,如果给ls作为参数,是不可以的,因为在Linux中这个ls是一个独立程序,而windows中的dir就是可以的,因为cmd.exe是解释这个来执行的,而不是dir是个程序。但是我怎么搞,都启动不了A.exe。指定的可以告诉我一下怎么弄。
但是这种过程是有个问题的,就是cmd.exe不会主动退出,也就是A.exe运行完了,cmd.exe也仍然在后台运行着,这又是个棘手的问题。
所以 QProcess直接启动 A.exe吧。
找到答案了,这样:QProcess用cmd运行其它进程_我是标同学的博客-CSDN博客
方式1:(用的老版的启动命令,但是编译会报一个警告,因为已经弃用了)
QProcess p;
QString str = "powershell.exe C:/Users/86132/Desktop/file/qtProject/IDE_NE/Lightning-Dir/build-Red_Panda_CPP-Desktop_Qt_5_15_2_MinGW_32_bit-Debug/RedPandaIDE/debug/kit/gcc-arm-none-eabi-9_2/bin/arm-none-eabi-gcc -Iuser -Iport -Ibsp/STM32F1xx_HAL_Driver/Inc -Ibsp/STM32F1xx_HAL_Driver/Inc/Legacy -Ibsp/CMSIS/Device/ST/STM32F1xx/Include -Ibsp/CMSIS/Include -Ikernel -Ilib/MALLOC -Ilib/NE_tool -Ilib/timeMeasure -Ilib -DUSE_HAL_DRIVER -DSTM32F103xE -dM -E C:/Users/86132/Desktop/file/qtProject/IDE_NE/Lightning-Dir/build-Red_Panda_CPP-Desktop_Qt_5_15_2_MinGW_32_bit-Debug/RedPandaIDE/debug/kit/tmp/foo1.c | findstr __GNUC__"
p.start(str);
方式2:(不会报警告)
QString program = "powershell.exe";
QStringList list;
list<<pMainWindow->project()->getCompilerPath(); //拿到gcc路径
list<<pMainWindow->project()->getIncludeHeaderPathsForGccList();
list<<pMainWindow->project()->getMacroDefinitionListForGccList();
list<<"-dM"<<"-E"<<getDir_tmp()+"/foo1.c"<<"|"<<"findstr"<<"\""+macrosWillJudge+"\"";
p.start(program, list);