Send stdin to a process from windows command prompt Send stdin to a process from windows command prompt windows windows

Send stdin to a process from windows command prompt


As far as I know this is not possible by basic cmd commands. PowerShell is more powerful though and can use the .NET framework from windows.

I found this PowerShell script which claims to pass text to an already opened cmd:

$psi = New-Object System.Diagnostics.ProcessStartInfo;$psi.FileName = "cmd.exe"; #process file$psi.UseShellExecute = $false; #start the process from it's own executable file$psi.RedirectStandardInput = $true; #enable the process to read from standard input$p = [System.Diagnostics.Process]::Start($psi);Start-Sleep -s 2 #wait 2 seconds so that the process can be up and running$p.StandardInput.WriteLine("dir"); #StandardInput property of the Process is a .NET StreamWriter object

Source: https://stackoverflow.com/a/16100200/10588376

You would have to safe this script with an .ps1 ending and run it.

A workaround to use this as a cmd command would be to make it accept arguments, so that you can run it with yourScript.ps1 procced_pid arguments for example.

The standard windows cmd is just too limited to fullfill such a task by its own.