0

In a Powershell script I would like to launch a process (a java program) using the batch "Start" command. The reason for using this is that I would like to have control over process priority as well as the CPU numa node and affinity assignment, and the only way I have found to do that is through batch "Start" (https://ss64.com/nt/start.html).

As an example, in Powershell I can run

cmd /c myprocess

without problems, but running

start /AboveNormal "windowname" myprocess

I get the error "Start-Process : A positional parameter cannot be found that accepts argument ... ". Running from a batch script it runs fine.

It looks to me like Powershell is trying to execute the command using the native "Start-Process", but I am not sure how to overwrite that. Any suggestions would be appreciated.

Hove
  • 1
  • `cmd /c start /AboveNormal "windowname" myprocess`? – Mathias R. Jessen Apr 16 '20 at 16:23
  • Then I get the error "cmd : The system cannot find the file windowname.". However, if I then remove "windowname" and run `cmd /c start /AboveNormal myprocess` it actually works. I'm not sure how, as the window title is a required argument for start (at least in batch scripting), but that is not so important I guess. Thank you for the suggestion :) – Hove Apr 16 '20 at 16:54
  • I am not that big of a Powershell user but just searching StackOverFlow I see a lot of Powershell answers for this question already. – Squashman Apr 16 '20 at 17:20
  • 1
    You're using PowerShell and under that, `Start` is an alias of `Start-Process`, if you take a look at the usage information for Start-Process, i.e. `Get-Help Start-Process -Detailed`, you'll find out all you should need. I might suggest something along the lines of `Start-Process -FilePath "$Env:ComSpec" -ArgumentList "/C Start \`"Window Title\`" /AboveNormal \`"C:\Users\Hove\My Directory\MyProcess.exe\`""`. – Compo Apr 16 '20 at 17:52
  • 2
    There is absolutely no need to use Windows command processor to start a Java application with a process priority above normal. PowerShell is much more powerful than Windows command processor and it is of course also possible with PowerShell to do that. Look for example on [Can I set PowerShell 'Start-Job' with low priority?](https://stackoverflow.com/questions/12995767/) and the link posted in question. Even better is [in PowerShell, set affinity in start-process](https://stackoverflow.com/questions/19250927/). – Mofi Apr 16 '20 at 18:05
  • The documentations needed are [Process Class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process) and [ProcessStartInfo Class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo) and in this case additionally [ProcessPriorityClass Enum](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processpriorityclass). Reading all __Process__ related documentations would be even better to get better knowledge on process management by Windows. – Mofi Apr 16 '20 at 18:15

1 Answers1

0

start is a cmd command, so launch it via cmd, just remember to escape quotes:

cmd /c "start ""windowname"" myprocess"
# or
cmd /c "start `"windowname`" myprocess"
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206