2

How does one run a background process in powershell on windows 7? The answers here: Powershell equivalent of bash ampersand (&) for forking/running background processes refer to *-psjob commands which seem to no longer exist.

I have found one other reference through google to psjob being missing, but no solutions.

Edit: apparently the solution involves a command called start-job.

UNFORTUNATELY it's not clear how to run a programme that takes parameters. I'm trying to run "rails server". When I just type rails server at the prompt, rails runs just fine, but it blocks my shell. I've tried various ways of invoking rails with the server argument, such as:

start-job -scriptblock {rails server}
start-job -scriptblock {"rails server"}
start-job -scriptblock {rails "server"}
start-job -scriptblock {rails} -argumentlist server
start-job -scriptblock {rails} -argumentlist "server"
start-job -scriptblock {rails $args[0]} -argumentlist server
start-job -scriptblock {rails $args[1]} -argumentlist server
start-job -scriptblock {rails $args[0]} -argumentlist @("server")

all to no avail

Community
  • 1
  • 1
Marcin
  • 48,559
  • 18
  • 128
  • 201
  • 1
    start-job will return a job; run receive-job to get the output returned from your attempts. Use get-job to get the status messages. Without any errors, we cannot help you. "Doens't work" is not useful. – x0n May 22 '11 at 16:00
  • @x0n: There are no powershell errors. – Marcin May 22 '11 at 19:54
  • Use ProcessExplorer and look for the process (rails) if it is created. Or ProcessMonitor, it might capture that process was created and then you can find command line parameters used. This can clarify if it is called with the right params or not. – stej May 22 '11 at 21:47

5 Answers5

2

Try this

Start-Job -scriptblock { param($p) rails $p } -ArgumentList "server"
Doug Finke
  • 6,675
  • 1
  • 31
  • 47
  • Unfortunately this doesn't work either - rails just outputs a usage message :( – Marcin May 22 '11 at 11:50
  • Substituting echo in place of rails shows that echo is being passed "server", so damned if I know what's happening. – Marcin May 22 '11 at 11:52
2

Random guess: Try fully-qualifying the path to rails.exe.

x0n
  • 51,312
  • 7
  • 89
  • 111
1

Have you tried using the New-PSSession cmdlet? This allows you to run commands under a new background session using PowerShell Remoting, even on the local machine.

$Session = New-PSSession localhost

Invoke-Command -Session $Session -ScriptBlock {Rails Server}

For more info:

help about_remote*

1

It's not very elegant but you could always make a batch file and call that. I do that for calling curl from PowerShell.

Matt
  • 1,931
  • 12
  • 20
0

Have a look to the function in powershell - passing parameters to exe

The function Call can interest you.

Community
  • 1
  • 1
JPBlanc
  • 70,406
  • 17
  • 130
  • 175