• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[PowerShell] Lower Memory Consumption When using "cmd /c" instead of ".\" to run exe?

Question

+Red King    2,466

I don't get this,

cmd /c " `"mysqldump.exe`" .. > $foo "
# vs
.\mysqldump.exe .. > $foo

PS process eats all my memory when using .\foobar.exe whereas going using cmd /c "foobar.exe" does not.

 

 

What the ###### is happening here? Ideas?

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
+rdlenk    150

Does the effect change at all if you use Start-Process?

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
+Red King    2,466
2 hours ago, rdlenk said:

Does the effect change at all if you use Start-Process?

I think that did the trick! I think PS tried storing the file in memory before writing it to disk with the ">" op,

With Start-Process and -RedirectStandardOutput - it does not try to store the file in memory.

 

Share this post


Link to post
Share on other sites
  • 0
+rdlenk    150

I don't think PowerShell likes using ">" anyways. Should be something like "<command> | Write-Output <filename>" or something like that.

Share this post


Link to post
Share on other sites
  • 0
+Red King    2,466

I need some follow up tips.

 

I noticed that Start-Process executes slower than "cmd /c" - any reason for that?

Share this post


Link to post
Share on other sites
  • 0
Riva    1,175
On 09/09/2016 at 2:49 PM, J. X. Maxwell said:

I need some follow up tips.

 

I noticed that Start-Process executes slower than "cmd /c" - any reason for that?

In both scenarios foobar.exe is a child process of either powershell or cmd instance. Powershell is a managed process (.NET CLR) vs. CMD which is native app. Native apps have a lighter footprint and higher processor resolution. .NET CLR (and Java) tend to use a virtualised CPU in order to ensure type safety. .NET native solves this problem but it isnt as widely implemented yet.

 

Share this post


Link to post
Share on other sites
  • 0
+Red King    2,466
10 hours ago, Riva said:

In both scenarios foobar.exe is a child process of either powershell or cmd instance. Powershell is a managed process (.NET CLR) vs. CMD which is native app. Native apps have a lighter footprint and higher processor resolution. .NET CLR (and Java) tend to use a virtualised CPU in order to ensure type safety. .NET native solves this problem but it isnt as widely implemented yet.

 

I don't think that explains it. I mean there is a difference between native and .NET but its minor for non-performance critical code. Like Start-Process just executes another executable and waits for it - so not much runs in .NET CLR anyway here.

 

As far as I remember (this topic is from a year ago and I don't work there anymore) - it just did nothing for a much longer time when launching from Start-Process versus indirectly through CMD. Like it wasn't an issue with higher process utilization - mysqldump through Start-Process was simply doing ######-all for a long time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.