如何正确使用system()在C ++中执行命令? [英] How to properly use system() to execute a command in C++?
问题描述
我是Windows下的C ++编程的新手。我试图执行一个命令说: cuobjdump
在C ++代码使用 system()
函数:
I am new to C++ programming under Windows. I am trying to execute a command say cuobjdump
in C++ code using the system()
function:
system("C:\\program files\\nvidia gpu computing...\\cuobjdump.exe --dump-cubin C:\\..\\input.exe");
输出:
Usage : cuobjdump [options] <file>
随后是cuobjdump的选项列表。
This followed by the list of the options for cuobjdump.
当我执行这个程序,我总是得到cuobjdump帮助选项显示在命令行。就像系统调用不解析文件名一样。我做错了什么?我得到相同的结果,而使用createprocess。选项 - dump-cubin
给出一个错误,如同我错了。
When I execute this program I always get the cuobjdump help options displayed in the command line. It's as if the system call does not parse the filename. What am I doing wrong? I get the same result while using createprocess. The options --dump-cubin
gives an error as if I mistyped it.
推荐答案
尝试一下(即,用包围cuobjdump.exe路径,在C ++中正确转义为
\
):
Give a try with (that is, surrounding cuobjdump.exe path with "
, properly escaped in C++ as \"
):
system("\"C:\\program files\\nvidia gpu computing...\\cuobjdump.exe\" --dump-cubin C:\\..\\input.exe");
这篇关于如何正确使用system()在C ++中执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!