0

我需要从我的程序运行 windows powershell 脚本。为此,我只需使用包含脚本主体本身的字符串 arg 启动 powershell 进程:

 Process.Start("powershell.exe", "my script body..");

它有效。但我还需要将一些参数传递给脚本。它应该看起来像:

Process.Start("powershell.exe", "some args my script body..");
  • 这是个问题。我知道这是可能的。我什至找到了description,但那里没有这样的例子。请帮忙
4

2 回答 2

2

文档中,您应该能够执行以下操作:

process.Start("powershell.exe","-noprofile -file c:\temp\test.ps1 TEST -noexit")

其中 TEST 是传递给脚本的参数

重新阅读您的问题后进行编辑:

process.Start("powershell.exe","-noprofile -command {write-host $args[0] } -args 'test'")
于 2013-06-18T13:38:54.923 回答
0

工作解决方案:

Process.Start("powershell.exe", "-noexit -command &{write-host $args[0]} arg1Value arg2Value");
于 2013-06-20T10:04:30.140 回答