首页 > 解决方案 > 命令行在命令提示符下有效,但在 VB.NET 中无效

问题描述

我的命令:

c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log 

当由命令提示符执行时,这可以正常工作。

但是从VB.NET,它不起作用(日志文件被创建但空白,日志文件应该包含abc.exe的日志进程,abc.exe也没有执行)。

Dim p as Process = new Process() 
Dim pi as ProcessStartInfo = new ProcessStartInfo() 
pi.Arguments = "/C c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log " 
pi.FileName = "cmd.exe" 
p.StartInfo = pi 
p.Start()
p.WaitForExit() 

为什么?

更新:在等待解释时,这是我的解决方法。

Dim p as Process = new Process() 
Dim pi as ProcessStartInfo = new ProcessStartInfo() 
pi.Arguments = "c:\temp\abc.ini" 
pi.FileName = "c:\temp\abc.exe" 
p.StartInfo = pi 
p.Start()
Dim output as String = p.StandardOutput.ReadToEnd()
p.WaitForExit() 

WriteLog("c:\temp\log.log", output)

标签: vb.netprocesscommand

解决方案


推荐阅读