我读过这个答案堆栈溢出 https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes答案让我成功了一半。这是我需要做的。
执行这个命令:
"c:\myexe.exe <c:\Users\Me\myanswerfile.txt"
如果我直接从我的 powershell 脚本中运行它
&'c:\myexe.exe <c:\Users\Me\myanswerfile.txt'
我收到此错误:
The term 'C:\myexe.exe <c:\Users\Me\myanswerfile.txt' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the spelling of the name,or
if a path was included, verif that the path is correct and try again.
现在我尝试了几种变体,包括将原始命令放入名为 $cmd 的变量中,然后传递
如果我将“
我很困惑。有什么建议么?
如果你想运行一个程序,只需输入它的名称和参数:
notepad.exe C:\devmy\hi.txt
如果您想运行一个 exe 并将标准输入重定向到它,您的示例似乎是尝试这样做,请使用:
Get-Content c:devmy\hi.txt | yourexe.exe
如果您需要指定程序的完整路径,那么您需要使用 & 符号和引号,否则 powershell 会认为您正在定义一个纯字符串:
&"C:\Program Files (x86)\Notepad++\notepad++.exe"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)