使用参数在单独的Process中运行powershell脚本 [英] Running powershell script in separate Process with arguments

查看:81
本文介绍了使用参数在单独的Process中运行powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个单独的进程中调用一个powershell脚本字符串,但似乎我没有将任何参数传递给脚本。有没有办法在单独的进程中调用powershell脚本



I am trying to invoke a powershell script string in a separate process but seems like I am not getting any argument passed to the script. Is there a way to invoke powershell script in a separate process

private static void InvokeScript(int arguments)
     {
         Process p = new Process();
         p.StartInfo.FileName = "powershell.exe";
         p.StartInfo.Arguments = String.Format("{0}\"\"{1}\"\"", update, arguments);
         p.StartInfo.RedirectStandardOutput = true;
         p.StartInfo.RedirectStandardError = true;
         p.StartInfo.UseShellExecute = false;
         p.Start();
         var output = p.StandardOutput;
         var error = p.StandardError;
         string result = output.ReadToEnd();
         string errorstring = error.ReadToEnd();
         p.WaitForExit();
     }










 private const string update = @"
try
{    
    return $($args.count)
}
catch
{
    return $_.Exception.Message
}";

推荐答案


args.count)
}
catch
{
return
args.count) } catch { return


_。异常。消息
};


这篇关于使用参数在单独的Process中运行powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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