2011-10-17 141 views
6

私はpowershellを使って別のpowershellスクリプトを実行しています。ある時点で他のスクリプトが入力を求めていますが、私は他のスクリプトの出力を読むことができますそれに入力を供給する。あなたがbashで期待してできることと似ています。bashに相当するpowershellの "expect"

アイデア?

ありがとうございました

答えて

0

PowerShellでExpectプログラムを使用するだけです。できます。 Powershellはシェルでもあります。powershellによって書かれたコードを実行することができます。これは、powershellを再度呼び出すbashコードを呼び出します。

ベローはテストです。

It "can work with tcl expect" { 
    $bs = @' 
    echo "Do you wish to install this program?" 
    select yn in "Yes" "No"; do 
    case $yn in 
     Yes) echo "install"; break;; 
     No) exit;; 
    esac 
done 
'@ 

$bsf = New-TemporaryFile 
$bs | Set-Content -Path $bsf 

$tcls = @' 
#!/bin/sh 
# exp.tcl \ 
exec tclsh "$0" ${1+"[email protected]"} 

package require Expect 
set timeout 100000 
spawn {spawn-command} 
expect { 
    "Enter password: $" { 
     exp_send "$password\r" 
     exp_continue 
    } 
    "#\? $" { 
      exp_send "1" 
    } 
    eof {} 
    timeout {} 
} 
'@ 

$tclf = New-TemporaryFile 
$tcls -replace "{spawn-command}",("bash",$bsf -join " ") | Set-Content -Path $tclf 
"bash", $tclf -join " " | Invoke-Expression 

Remove-Item $bsf 
Remove-Item $tclf 
} 

テストを説明しましょう。

  1. 入力が必要なbashファイルを作成します。
  2. ステップ1で作成したbashを呼び出すtclファイルを作成します。
  3. powershellからtclプログラムを起動すると、動作し、入力を待機しません。
0

誰かを助けることができるように自分のソリューションを投稿するだけです。私は同じ問題に直面し、答えを求める他のスクリプトを実行していました。最初に、各行の各質問に対する回答を順番に入力して "inputFileLocation.txt"というファイルを作成します。次に、以下の構文でスクリプトを実行します。そしてそれは仕事をするでしょう。

`cmd.exe /c "script.bat < inputFileLocation.txt"` 
関連する問題