CreateProcess 和命令行参数
背景信息: Windows 7、Visual C++ 2010 Express
问题: CreateProcess() 不断返回“无效的命令行参数”
说明: 我编写一段使用 Windows API 的 CreateProcess 调用外部程序的代码。到目前为止,我已经接到了使用一个外部程序的电话:
if( !CreateProcess( "C:\\Temp\\convert.exe",
t_str, // Arguments
...
}
//where t_str is " C:\\img1.jpeg C:\\img1.pgm" (ImageMagick if you're wondering).
即使我为了将所有内容推送到 Windows 字符串和指针中而进行了大量的数据修改,它也能完美地工作。因此,我复制了 CreateProcess() 的所有修改,以便再次调用不同的外部程序:
if( !CreateProcess( "C:\\Temp\\sift.exe",
t_str2, // Arguments
...
}
//where t_str2 is ` < C:\\img1.pgm > C:\\img1.key`
基本上,非常相似,但所有变量名称都已更改(因为我有这两个调用串行运行)。这就是问题所在;这不会运行,而是打印出“无效的命令行参数:< C:\img1.pgm”。当然,这个命令在命令提示符下工作得很好,但在我的代码中却不行。
我将 t_str2 切换到其他不太复杂的东西(因为我知道 sift.exe 是如何工作的),并且得到了相同的结果。当我只运行筛选而不转换时,也会发生同样的情况。
问题:什么可能导致此问题?我可以做什么来进一步调试这个问题?关于我正在使用的方法的替代方案有什么建议吗?任何帮助表示赞赏。我可以提供更多代码,但它非常简单,并且不会出现太多问题。
Background Info: Windows 7, Visual C++ 2010 Express
Problem: CreateProcess() keeps returning with 'Invalid command line argument'
Explanation: I'm writing a piece of code that calls external programs using the Windows API's CreateProcess. I've gotten the call to work with one external program so far:
if( !CreateProcess( "C:\\Temp\\convert.exe",
t_str, // Arguments
...
}
//where t_str is " C:\\img1.jpeg C:\\img1.pgm" (ImageMagick if you're wondering).
This works perfectly even with the amount of data-mangling I did to push everything into the Windows strings and pointers. So I copied all of the mangling for CreateProcess() for another call to a different external program:
if( !CreateProcess( "C:\\Temp\\sift.exe",
t_str2, // Arguments
...
}
//where t_str2 is ` < C:\\img1.pgm > C:\\img1.key`
Basically, something very similar, but with all the variable names changed (since I have these two calls running serial). And this is where the problem is; this doesn't run, and, instead, prints out "Invalid command line argument: < C:\img1.pgm". Of course, this command works fine in the command prompt, but not in my code.
I switched t_str2 to something else a little less complicated(since I know how sift.exe works) and I get the same result. Same thing happens when I run just sift and not convert.
Question: What could be causing this problem? What could I do to further debug this problem? Any suggestions on alternatives to the methods I'm using? Any help is appreciated. I can provide further code, but It's pretty straight forward, and not much could go wrong with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
