Send stdin to a process from a windows command prompt

On Windows, I have console programs that run in the background with a hidden console. Is there any direct input to the program console? I want to be able to do something like:

echo Y| *the_running_process_here*

to send Y to the 'stdin process.

+8
source share
2 answers

If I understand correctly, you need to send the output from some command to the input for another command. You can use the pipe "|" for this.

http://commandwindows.com/command1.htm

Here is a link to command line options. Hope this helps.

+1
source

, cmd. PowerShell , .NET Framework Windows.

PowerShell, , cmd:

$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.FileName = "cmd.exe"; #process file
$psi.UseShellExecute = $false; #start the process from it 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

: fooobar.com/questions/259706/...

.ps1 .

cmd , , , , yourScript.ps1 procced_pid arguments.

cmd , .

0

Source: https://habr.com/ru/post/1744281/


All Articles