【问题标题】:Too fast to read result读取结果太快
【发布时间】:2015-02-25 11:55:43
【问题描述】:

我的代码有问题。 我想执行文件夹实用程序中的命令行“convert.exe Capture.PNG Capture.bmp”。 所以我想为它创建一个流程。

STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD ExitCode;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
CString command="convert.exe "+CurrentDirectory()+"\\Utility\\Capture.PNG "+CurrentDirectory()+"\\Utility\\Capture.bmp >text.txt";
char test[1000];
memccpy(test,command,1,command.GetLength());
CString application=CurrentDirectory()+"\\Utility\\convert.exe";
if(CreateProcess(application, test,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL, &si, &pi))
{ 
    WaitForSingleObject(&pi.hProcess,INFINITE);
    printf("Yohoo!");
}  
else
{
    printf("The process could not be started...");
}

程序在“if”中输入,但我没有我的位图。 我不知道如何在控制台中写入错误。它会很快自行关闭。

我的代码在 MFC C++ Visual Studio 2012 中...而 convert.exe 是 ImageMagick 的应用程序,无需安装。

谢谢

【问题讨论】:

  • 看这里:codeproject.com/Tips/333559/CreateProcess-and-wait-for-result 这显示了如何从启动的进程中获取返回码,这可能有助于调试
  • 请注意,Windows 有一个 convert 命令,可以代替 ImageMagick convert(或您正在使用的任何东西)执行,例如如果PATH 不太正确。
  • 为什么不直接使用标准库的system

标签: c++ mfc imagemagick


【解决方案1】:

关于声明

CString command="convert.exe "
    + CurrentDirectory() + "\\Utility\\Capture.PNG "
    + CurrentDirectory() + "\\Utility\\Capture.bmp >text.txt";

您不能将重定向运算符<> 与普通命令行一起使用到CreateProcess。重定向操作符是各种命令解释器的一个特性。如果你愿意,启动这样一个命令解释器,例如cmd /c "mycommandblahblah > somefile".

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多