【问题标题】:Run powershell script from within a powershell script从 powershell 脚本中运行 powershell 脚本
【发布时间】:2014-02-03 19:19:02
【问题描述】:

我有一个 perl 脚本 perl1.pl。 在 perl 脚本中,我调用了一个 powershell 脚本 script1.ps1。 在 script.ps1 中,我使用局部变量作为参数调用其他脚本,例如 script2.ps1。 我准备了一个powershell脚本script3.ps1。 我想从 script1.ps1 与 script2.ps1 并行运行 script3.ps1。 我需要传递 sample_script2.ps1 运行的相同参数(局部变量作为参数)。 首先需要调用 script3,然后调用 script2。

我已经尝试过如下所示的 powershel.exe

C:..\powershell.exe -FilePath script3.ps1 $a,$b,$c

我已经包含了绕过,执行策略。$a $b $c 是局部变量。但是似乎发生的是命令行打开(因为它是我们的脚本被调用的方式)并开始执行 script1.ps1 以及何时它涉及到上面提到的命令它停止。我在上面的命令行中输入“exit”然后script2启动。

我怎样才能达到同样的效果,即 script3.ps1 与 script2.ps1 的并行运行。

【问题讨论】:

    标签: powershell parallel-processing invoke-command start-job


    【解决方案1】:

    我不太精通 PowerShell,但我知道您可以运行 background jobs in PowerShell

    当 cmdlet 作为后台作业运行时,工作在其自己的线程中异步完成...

    您要用于创建后台作业的 cmdlet (command-let) 是 Start-Job

    Start-Job -FilePath c:\scripts\sample.ps1
    

    此命令将 Sample.ps1 脚本作为后台作业运行。然后你可以使用Receive-Job 来获取你所有工作的产出。

    Similar Question?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 2019-12-02
      • 2019-09-30
      • 2021-09-11
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      相关资源
      最近更新 更多