2017-02-03 4 views
0

をお読みください。スタートプロセスとStandardOutput

[Diagnostics.Process]::Start("C:\test.exe","-verbose -page") 

この意志私はと対話することができ、新しいウィンドウの魔女を開くが、私はそれのために出力をリダイレクトすることはできません(出力Iキーを押しますと、メッセージなどのウィンドウで全体の相互作用を意味する)

だから私は、私が試みることができると思った。

Start-Transcript -path "C:\test.txt" -append 

$ps = new-object System.Diagnostics.Process 
$ps.StartInfo.Filename = "C:\test.exe" 
$ps.StartInfo.Arguments = " -verbose -page" 
$ps.StartInfo.RedirectStandardOutput = $True 
$ps.StartInfo.UseShellExecute = $false 
$ps.start() 

while (! $ps.HasExited) { 
    write-host = $ps.StandardOutput.ReadToEnd(); 
} 

ここで私は出力が得られますが、やりとりがないので、同じまたは別のコンソールでこのプロセスを開始し、ファイルとのやりとりをキャッチするためのオプションや手順が必要です。

アプリケーションがキーを押すことを頼むことがありますが、このアプリケーションがコンソールウィンドウを測定してid出力が適合するかどうかチェックするため、

このようなことは可能ですか?

答えて

0

を行うことができるはずそれが正しいと私は私のソリューションを切断している。

押しボタン機能を継続する:

Function Press-Button 
{ 
    Add-Type -AssemblyName System.Windows.Forms 
    [System.Windows.Forms.SendKeys]::SendWait('~'); 
} 

スタートプロセスを、継続してトランザクション全体と押してログインします。

Function Run-Tool 
{ 
    Start-Transcript -path "C:\test.txt" -append 

    $ps = new-object System.Diagnostics.Process 
    $ps.StartInfo.Filename = "C:\test.exe" 
    $ps.StartInfo.Arguments = " -verbose -page" 
    $ps.StartInfo.RedirectStandardInput = $true; 
    $ps.StartInfo.UseShellExecute = $false 
    $ps.start() 

    while (! $ps.HasExited) 
    { 
     Start-Sleep -s 5 
     write-host "I will press button now..." 
     Press-Button   
    } 

    Stop-Transcript 
} 
1

あなたは、最終的に私私はPowerShellで対話のこの種の大きな問題を抱えていたように、私は、コンソールアプリケーションを押しキーを実行する意味

myprocess.StandardInput.WriteLine("some input"); 

または

myprocess.StandardInput.Write(" "); 
0

どんなにあなたがこれを行う方法は、アクティブなシステムでは信頼できないことはないだろう。

Function Run-Tool { 
    Start-Transcript -path "C:\test.txt" -append 
    Add-Type -AssemblyName System.Windows.Forms 

    $ps = new-object System.Diagnostics.Process 
    $ps.StartInfo.Filename = "C:\test.exe" 
    $ps.StartInfo.Arguments = " -verbose -page" 
    $ps.StartInfo.RedirectStandardInput = $true; 
    $ps.StartInfo.UseShellExecute = $false 
    $ps.start() 

    do{ 
     Start-Sleep -s 5 
     write-host "I will press button now..." 
     [System.Windows.Forms.SendKeys]::SendWait('~'); 
    } 
    until($ps.HasExited) 
    Stop-Transcript 
} 
関連する問題