Jump to content

Recommended Posts

Posted

In Windows 10 Powershell I'm able to run:

(Get-Item "c:\windows\system32\cmd.exe").VersionInfo.ProductVersion

I get  this result :

10.0.19041.1

 

I'd like to run this command and using these variables:

$PSH = "powershell"

$myExePath = "c:\windows\system32\cmd.exe"

$CMD = $PSH & '(Get-Item "$myExePath").VersionInfo.ProductVersion'

$result = Runwait(@ComSpec & " /c " & $CMD, "", @SW_HIDE)

 

How can I make it ?

Posted
$CMD = $PSH & '(Get-Item "' & $myExePath & '").VersionInfo.ProductVersion'

 

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Posted (edited)

And another one:

 

$result = Runwait(@ComSpec & " /c " & $CMD, "", @SW_HIDE)

this will give you the exit code, not the result of your program.

 

To catch the "output" you would need to read the output by using StdoutRead()

#include <AutoItConstants.au3>

$PID = Run($YourCommand, $WD, @SW_HIDE, $STDERR_MERGED) ; run(), do not use runwait()

while ProcessExists($PID)
    sleep(200)
wend

$Output=StdoutRead($PID)
StdioClose($PID)

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...