Make Foreground a Job-Based Job Launched by Start-Job in Powershell for Windows

In Bash, you can run a task in the background by placing it &at the end of the command. It is also possible to bring this task to the forefront using a command fgwith the appropriate task identifier, if necessary.

In Powershell, I understand that the equivalent &is a command Start-Job. However, I can not find any information on the equivalent execution methods fg. Is there any way to do this? Note that I am not asking for a way out. Rather, my question is this.

Is there a way to bring current work to the forefront by taking control of the Powershell window?

The main reason this function is needed is because I can send keys / strings to the current job.

Using Windows 8.1 Pro.

+4
source share
1 answer

I burn midnight oil and hit my head in a google search after a google search. Turns out it's pretty easy using invoke-item .

Here is how I use it:

invoke-item .\form.ps1
timeout /t 90
wmic Path win32_process Where "CommandLine Like '%form.ps1%'" Call Terminate

This will call my script form.ps1(a Windows form I created) from PowerShell. The parent will continue execution while it is running form.ps1.

I use

wmic Path win32_process Where "CommandLine Like '%form.ps1%'" Call Terminate

to kill a form by the name of its command line.

0
source

All Articles