相关疑难解决方法(0)

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). 
Run Code Online (Sandbox Code Playgroud)

即使我将所有数据都推送到Windows字符串和指针中,我也可以完美地工作.所以我复制了CreateProcess()的所有修改,以便对另一个外部程序进行另一次调用:

 if( !CreateProcess( "C:\\Temp\\sift.exe",
     t_str2,        // Arguments
     ...
 }
 //where t_str2 is ` < C:\\img1.pgm > C:\\img1.key`
Run Code Online (Sandbox Code Playgroud)

基本上,一些非常相似,但所有变量名称都已更改(因为我有两个调用运行串行).这就是问题所在; 这不会运行,而是打印出"无效的命令行参数:<C:\ img1.pgm".当然,这个命令在命令提示符下工作正常,但在我的代码中没有.

我将t_str2切换到其他一些不太复杂的东西(因为我知道sift.exe如何工作),我得到了相同的结果.当我只进行筛选而不是转换时,会发生同样的事情.

问题:可能导致此问题的原因是什么?我该怎么做才能进一步调试这个问题?关于我正在使用的方法的替代方案的任何建议?任何帮助表示赞赏.我可以提供进一步的代码,但它非常直接,并没有太多可能出错.

c++ windows createprocess command-line-arguments

4
推荐指数
1
解决办法
1万
查看次数

如何运行外部程序?

我在Linux薄荷12.

我想运行一个程序usr/share/application/firefox,然后在任何地方传递一个字符串.我还没有找到适用于Linux的解决方案,但从目前为止我所看到的,Windows有很多理论.

size_t ExecuteProcess(std::wstring FullPathToExe, std::wstring Parameters, size_t SecondsToWait) 
{ 
    size_t iMyCounter = 0, iReturnVal = 0, iPos = 0; 
    DWORD dwExitCode = 0; 
    std::wstring sTempStr = L""; 

    /* - NOTE - You should check here to see if the exe even exists */ 

    /* Add a space to the beginning of the Parameters */ 
    if (Parameters.size() != 0) 
    { 
        if (Parameters[0] != L' ') 
        { 
            Parameters.insert(0,L" "); 
        } 
    } 

    /* The first parameter needs to be the …
Run Code Online (Sandbox Code Playgroud)

c++ linux

3
推荐指数
1
解决办法
1万
查看次数