简体   繁体   中英

Performance: System.Diagnostics.Process vs System.Management.Automation.PowerShell

In this blog post by PowerShell Team, they focused on posh commands.

  1. Is there a way to call Create() without loading any PS command, to make it act like a system process executor (substitute of System.Diagnostics.Process )? How would we go about executing the following with System.Management.Automation.PowerShell :

     node.exe some_module input_file_path --switch1 --switch2=value2 
  2. If 1 is possible, next question; would this perform faster than Diagnostics.Process.Start() ?

  3. Is there a way to keep the instance of PS invoked in an interactive mode (in a background thread), running node.exe in an interactive mode listening to the calls from IRemoteSource ? As opposed to; invoke , execute command and close for each call.

  4. Would this, the interactive mode way, boost performance (given IRemoteSource is calling too frequently with large chunks of node.js commands)?

Yes it is possible and simple:

ps.AddScript("node.exe some_module input_file_path --switch1 --switch2=value2");

Regarding #2, I doubt it would be faster as there is more machinery to spin up to support the PowerShell engine/workspace. Regarding #3 & #4 you need to explain a bit more about what you need here. What is an IRemoteSource and how does that interact with node.exe? FWIW you can execute the PowerShell engine on another thread and the ps.Invoke() call will not return as long as node.exe is running. If you need interaction between the host app and node.exe you can look at implementing the PowerShell host interfaces .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM