我一直在尝试运行一个应用程序, 并将其输出到文件。 然而, 我遇到一些问题, 需要命令线参数来这样做 。
这是我使用 ipconfig
解决问题的例子。
下列命令工作 :
ipconfig > output.txt
这将创建文件, 但不会以 ipconfig
输出来填充文件 :
start /D "C:>WINDOWSsystem32" ipconfig.exe > output.txt
我认为是使用 start
引发了这一问题,但我不确定。
<强 > 溶解 强 >
这就是能解决我问题的代码:
char path[500]; // Create character array
strcpy (path, "cd "); // Copy cd into the array
strcat (path, toolLocation); // Copy the path of the tool into the array
strcat (path, " & ip.exe > output.txt"); // Append on the name of the exe and output to a file
system (path); // Run the built array
我正在创建一个字符阵列, 然后附加给它。 这里的关键部分是系统呼叫中使用的 < code_ amp; code> 。 这是作为 < code > 和 code > 操作的, 并且在执行. exe 文件之前先使用目录的 cd ing 。