vb.net - 命令行在命令提示符下有效,但在 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)
解决方案
推荐阅读
- shell - 想在ansible playbook中使用lineinfile在文件中插入文本
- c++ - 背后的原因:局部变量“派生”将被复制,尽管按名称返回
- vala - 如何将多编译器参数添加到 meson.build
- java - 在单独的 JSP 文件中调用 Connection 对象期间获取空值
- javascript - 当我通过数据数组进行映射时,如何避免文本块和/或 div 相互重叠
- flutter - 你如何在 2 个 Flutter 项目之间共享代码?
- r - 基于另一个矩阵创建矩阵包含具有 na 值的元素的索引
- reactjs - 与 Typescript 反应:“never[]”类型的参数不可分配给“StateProperties |”类型的参数 (() => 状态属性)'
- php - 我应该使用哪种雄辩的关系?
- ios - 用户选择日期后无法显示“今天”而不是今天的日期