1

我正在使用 shell32.dll 中的 ShellExecuteW:

int value= ShellExecuteW(0, "open", "C:\test.bat", strParameters, "", 1);

批处理文件运行一个似乎打开但返回错误的 java 应用程序,并且控制台窗口很快关闭。

我想从控制台捕获错误。我尝试在批处理文件中的命令末尾添加以下重定向:

> output.txt 

2> output.txt 

> output.txt 2>&1

1> output.txt 2>&1

| output.txt

我希望这些常用命令能够工作,但它们都不会导致在 output.txt 中写入任何内容。我在这里做错了什么?

我正在使用 Metatrader5(MQL5 语言)从中调用 shellexecuteW。

谢谢您的回复。

4

1 回答 1

0

首先,由于 mql5 安全策略,您应该将 bat 文件放在“File”文件夹中的终端路径中,其次将这些代码放入您的脚本中以正确使用“ShellExecuteW”功能。

#import "shell32.dll"
        int ShellExecuteW(int hwnd,string operation,string file,string parameters,string directory,int showCmd);
#import
int result;
    string strParameters = "";
    string filename="test.bat";
    string Batfile_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH)+"\\Files\\"+filename;
    Print("Batfile_path:",Batfile_path);
  result = ShellExecuteW(0, "open", Batfile_path, strParameters, "", 0);

   if(result <= 32)Print("Shell Execute for running bat file Failed: ", result);
于 2020-08-11T14:45:17.120 回答