Interacting with existing process

Welcome Forums General PowerShell Q&A Interacting with existing process

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 4 months ago.

  • Author
  • #57382

    Points: 0
    Rank: Member

    Greetings all,

    I'm new to Powershell (and scripting in general) and have not had any luck with finding an answer to my question through searching.

    I have a batch file which starts an executable that continually runs in the background. The executable hijacks the command window to allow user input into the window in order to start tasks and cleanly exit the program. I would like to schedule a task that inputs the “Backup” command into the cmd window and preferably waits to receive the “Task Complete” message before continuing with other tasks before exiting.

    I currently have the below code which allows me to start cmd.exe, run the program (I made a simple batch file which mimics the executable called Infinate.bat), and input commands to the program.

    $psi = New-Object System.Diagnostics.ProcessStartInfo;
    $psi.FileName = "cmd.exe"
    $psi.UseShellExecute = $false
    $psi.RedirectStandardInput = $true
    $p = [System.Diagnostics.Process]::Start($psi)
    $p.StandardInput.WriteLine("title Infinate") 
    Start-Sleep -s 2

    What I want to do now is break the input of the Backup command into a new script which I can schedule in the task scheduler (or run as a one off). I have so far been unable to find a way to reattach the StandardInput to a new Powershell instance. I currently find the correct process using the window title but the $process.StandardInput property, while it exists, appears to have a null value. The last line of the below code gives an error of “You cannot call a method on a null-valued expression.”.

    $processes = Get-Process cmd
    foreach ( $process in $processes )
        if ( $process.mainWindowTitle -eq "Infinate" )
            $infinateProcess = $process
  • #57386

    Points: 0
    Rank: Member

    Streams are empty because you not the owner of a processes and you not launch it (and thus doesnt fill RedirectStandardInput 🙂 )

    I'm found something that looks like you want (not tested)

The topic ‘Interacting with existing process’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort