2

I have the exe from Lenovo that only provides command line output when run from a cmd window but not from PowerShell. The output seems to come from a ghost source other than StdOut or StdErr.
https://download.lenovo.com/pccbbs/mobiles/n2hgc06w.exe (you have to run and click install but all that does is unzip to c:\drivers\win\touchpadfw). Be sure to cancel the install prompt after extract.

This command gives me output to the console

& cmd.exe /c c:\drivers\win\touchpadfw\touchpadfw_aug2019\synreflash.exe /v /S 2

This also gives me output the the console and nothing in the variable

$var = (& cmd.exe /c c:\drivers\win\touchpadfw\touchpadfw_aug2019\synreflash.exe /v /S 2) 2>&1

Same here

$var = (& cmd.exe /c c:\drivers\win\touchpadfw\touchpadfw_aug2019\synreflash.exe /v /S 2 2>&1) 

I feel like this exe is outputting in some other way than StdOut and StdErr but I don't know what. Nothing I've tried can capture what it is outputting. Is there a third method of output?

This is where it gets weird. Using "start cmd" to open a cmd window from the admin PowerShell, I run the exe directly in the cmd window but the output goes to the parent powershell console. I cannot get any output if I start the cmd window as admin directly.

2
  • Have you tried redirecting all output with *>&1? Commented Feb 3, 2020 at 18:13
  • @Iconiu, let me know if the updated solution below answers your questions, if yes, you can click the green tickbox to mark as resolved. Cheers !! Commented Feb 19, 2020 at 18:42

1 Answer 1

1

Look at the SynReflash usage below you will notice that you would need to pass the last arg as /S 3 explicitly, to print to Standard Output as opposed to /S 2 is a silent mode


enter image description here

$cmdOutput = cmd.exe /c "C:\DRIVERS\WIN\TouchpadFW\n2hgc06w\synreflash.exe" /v /S 3 '2>&1'

OR


proc = [System.Diagnostics.Process]::Start([System.Diagnostics.ProcessStartInfo]@
{
    'FileName'               = "cmd.exe"
    'Arguments'              = "/C " + """C:\DRIVERS\WIN\TouchpadFW\n2hgc06w\synreflash.exe"" /v /s 3"
    'CreateNoWindow'         = $true
    'UseShellExecute'        = $false
    'RedirectStandardOutput' = $true   # to get stdout to $proc.StandardOutput
    'RedirectStandardError'  = $true   # to get stderr to $proc.StandardError
})
$output = $proc.StandardOutput
$error1 = $proc.StandardError
write-host $output.ReadToEnd()


Output

FW Version: 1.2

Sign up to request clarification or add additional context in comments.

3 Comments

I appreciate your efforts but they do not work with this executable. The first example looks like you are redirecting to a file then trying to read it's content. The sample variable of $stdderror= "Error" is confusing as start-process wants a file name. Giving it one results in empty files. It does output to the console of the parent powershell window, the one used to start powershell_ISE. In the second example, both standardoutput and standarderror remain empty. I changed the /s 2 to /s 1 to make sure the exe was running and will output in it's own window.
In my first example variable thats storing Get-Content was incorrect, I edited my answer
@Iconiu Can you please confirm if the updated solution answered your questions, if yes, you can mark as resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.