0
votes

I have a powershell script that needs to run another .exe file as part of its job.

The .exe file itself spawns an interactive shell that I would like to write and read from mulitple times (without killing the .exe process in between).

For example, I'd like to run something like this from Powershell:

& my.exe

And then interacting with that process in the following way so I can read and write to the process's stdin/stdout of the spawned shell, which looks like this:

MY.EXE> <something sent from powershell> <Output that powershell can read> MY.EXE> <something sent from powershell> <Output that powershell can ready>

etc.

And eventually kill the .exe process when I'm done.

I've played around with manual process spawning in Powershell and overriding StdIn/StdOut/StdErr, but this seems flakey at best.

Any thoughts?

1

1 Answers

0
votes

in powershell we use start-job

$a = Start-Job -ScriptBlock {Get-Process }
$a | Receive-Job

you can delete job with Remove-Job
this job work at shell you opened but some job added by task scheduler you can add task run job one time or per minute run job and you can delete the scheduler

schtasks /create /tn TaskName /tr TaskRun /sc minute [/mo {1 - 1439}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain]user /p password]] [/ru {[Domain]User | "System"} [/rp Password]]

schtasks /create /sc minute /mo 30 /tn "powershellscript" /tr c:\1.ps1 
schtasks /query
schtasks /delete 

for run programm at background you can use function

 function bg() {Start-Process -NoNewWindow @args}
bg some.exe

for stop that program you can

 Get-Process -Name some.exe | Stop-Process