【发布时间】:2013-07-18 07:29:33
【问题描述】:
我正在从命令提示符运行以下命令
dir > c:\log.txt 2>&1
out 成功定向到c:\log.txt 文件。
然后,使用 CreateProcessA 运行相同的命令,如下所示,没有任何反应
Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
start.cb = Len(start)
start.dwFlags = 1
start.wShowWindow = 1
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
ret = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
这里cmdline$被传递为dir > c:\log.txt 2>&1
我试过Batch file - How to redirect output from exe after it has terminated?和Display & Redirect Output
请指出这里有什么问题
【问题讨论】:
标签: shell winapi command-line vb6 cmd