【发布时间】:2015-05-04 21:15:32
【问题描述】:
在我正在执行的 PowerShell 窗口中:
Start-Process XXXXX.exe -ArgumentList "some valid arguments" -wait
-redirectStandardOutput "D:\\test1.txt"
得到:
Start-Process : This command cannot be executed due to the error: The system cannot find the file specified.
At line:1 char:14
+ Start-Process <<<< XXXXX.exe -ArgumentList "some valid arguments here" -redirectStandardOutput "D:\\test1.txt"
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
如果我省略 -redirectStandardOutput 参数(确实如此),我已检查启动过程是否按预期工作。
test1.txt 是一个新文件,不尝试追加。
令人惊讶的是,D:\ 上的 test1.txt 文件是在我运行该行时创建的,它仍然是空的。
有人知道这里发生了什么吗? 谢谢。
编辑
我发现如果我跑步:
Start-Process XXXXX.exe -ArgumentList "some valid arguments" -wait
-redirectStandardOutput "D:\\test1.txt"
它失败了(如最初发布的那样) 如果我跑:
Start-Process XXXXX.exe -ArgumentList "some valid arguments" -wait
它工作正常,但不会将控制台输出保存到文件中 如果我跑
Start-Process .\XXXXX.exe -ArgumentList "some valid arguments" -wait
-redirectStandardOutput "D:\\test1.txt"
它的工作原理与预期的差不多。 那么为什么我在使用重定向时需要指定路径,而当我不使用时它运行得很好呢?
编辑 概括问题;关于当前目录中的脚本/exe 要求允许运行 ./ 前缀的要求似乎有些不一致。当我不重定向输出时, ./ 不是必需的。任何人都知道这是否是预期的行为?
【问题讨论】:
-
不是同一个问题;这个问题是关于附加到现有文件的。我的文件是全新的。在 OQ 中添加了更多详细信息。
标签: powershell runtime-error start-process