开发者

How to properly use system() to execute a command in C++?

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");

output:

Usage  : cuobjdump [options] <file>

This followed by the list of the options for cuobjdump.

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 开发者_如何学JAVAthe 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.


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("cuobjdump --dump-cubin path\filename.exe");

That \f is interpreted by the compiler as a string escape sequence, try path\\filename.exe


Most obviously, \ is an escape character in C / C++ strings, so it has to be doubled if you want to use it literally.

system("cuobjdump --dump-cubin path\\filename.exe");


Assuming that path is correct, you have to use a double \\ within strings to represent a single \.


I suggest you to use CreateProcess, or ShellExecute / ShellExecuteEx since you are working on Windows. system and ShellExecute eventually calls CreateProcess only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜