powershell将多个参数发送到外部命令 [英] powershell sending multiple parameter to a external command

查看:93
本文介绍了powershell将多个参数发送到外部命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Powershell脚本运行外部exe.

I am trying to run a external exe from a powershell script.

此exe需要4个参数.

This exe wants 4 parameters.

我一直在尝试invoke-item,invoke-command和&的每个组合"C:\ program files \ mycmd.exe myparam"在C:\中创建了一个快捷方式,以消除路径中的空格.

I have been trying every combo of invoke-item, invoke-command, & 'C:\program files\mycmd.exe myparam', made a shortcut in C:\ to get rid of the spaces in the path.

我可以使它使用一个参数,但不能使用更多参数.我遇到各种错误.

I can make it work with one parameter, but not with more. I get various errors.

总而言之,如何向exe发送4个参数?

To sum up, how do you send 4 parameters to an exe?

推荐答案

最好以正楷形式显示.一旦了解到发生了什么,您就可以通过在每个参数之间使用逗号来缩短它.

It's best if shown in longhand. Once you see what's going on, you can shorten it down by just using commas between each argument.

$arg1 = "filename1"
$arg2 = "-someswitch"
$arg3 = "C:\documents and settings\user\desktop\some other file.txt"
$arg4 = "-yetanotherswitch"

$allArgs = @($arg1, $arg2, $arg3, $arg4)

& "C:\Program Files\someapp\somecmd.exe" $allArgs

...简写:

& "C:\Program Files\someapp\somecmd.exe" "filename1", "-someswitch", "C:\documents and settings\user\desktop\some other file.txt", "-yetanotherswitch"

这篇关于powershell将多个参数发送到外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆