Jump to content

Stdout does not give results


ptrex
 Share

Recommended Posts

Maybe it's my lack of experience with stdout(), but I have several problems with it.

Let' start with this one :

#include <Constants.au3>

ReadInfo()

Func ReadInfo()
local $info
$info = Run("wmic csproduct","",@SW_HIDE,2); WMIC is the MS Commandline WMI solution

While 1
    $line = StdoutRead($Info)
    
    ConsoleWrite($line)
    If @error Then ExitLoop
Wend

EndFunc

No result is given :D

PS : The wmic runs only on XP and later.

Any hint :P

Thanks

ptrex

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

No help from no one. :P

Can at least someone confirm the same behaviour ?

I this a bug or a limitation of AutoIT or a script error ?

thanks

ptrex

I test your script same behavior here.

I try to launch with @comspec /c without any success.

I am as you I don't know why the StdoutRead doc example is working and not yours.

I need Valik or DaveF to jump in this analysis. :">

Link to comment
Share on other sites

I test your script same behavior here.

I try to launch with @comspec /c without any success.

I am as you I don't know why the StdoutRead doc example is working and not yours.

I need Valik or DaveF to jump in this analysis. :">

@Jpm

I have more example that don't work.

Try to use the Windows PowerShell cmdline tool.

The same results.

I am glad you responded !!

regards

ptrex

Link to comment
Share on other sites

#include <Constants.au3>

$foo = Run(@ComSpec & " /c wmic csproduct", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")

That the test I did. Have a look.

The CMD does not end so I you run it from Scite and stop the debugging you will see a msgbox with the first line.

That's remain me a lot of discussion about some application not delivering the dtdout buffer before closing.

I don't remember if some go around as been found. :P

Link to comment
Share on other sites

Jpm

Thanks so far.

Let me kow if there was a solution found.

This would open up doors.

Because I intended to start using the MS PowerShell.

And this is has big potentials also for AutoIT !!

regards

ptrex

Edited by ptrex
Link to comment
Share on other sites

Looks like WMIC expects some kind of input if it's not being run by the shell, I fed it a CRLF and it worked OK for me:

Dim $pid, $ourOutput
     
  ; Open with connections to STDIN and STDOUT
     $pid = Run("wmic.exe csproduct", @SystemDir, @SW_HIDE, 3)
     
     StdinWrite($pid, @CRLF)
  ; Call with no string param to close STDIN
     StdinWrite($pid)
     
     While 1
         $ourOutput &= StdoutRead($pid)
         If @error Then ExitLoop
     WEnd
         
     MsgBox(0, "", $ourOutput)

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Ptrex, when writing a program called MP3 to OGG, i noticed that all the command line encoders wrote to the $STDERR_CHILD stream. They just simply didn't write to the STDOUT stream even though they should have. I think this could very well be your problem.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Looks like WMIC expects some kind of input if it's not being run by the shell, I fed it a CRLF and it worked OK for me:

Dim $pid, $ourOutput
     
 ; Open with connections to STDIN and STDOUT
     $pid = Run("wmic.exe csproduct", @SystemDir, @SW_HIDE, 3)
     
     StdinWrite($pid, @CRLF)
 ; Call with no string param to close STDIN
     StdinWrite($pid)
     
     While 1
         $ourOutput &= StdoutRead($pid)
         If @error Then ExitLoop
     WEnd
         
     MsgBox(0, "", $ourOutput)
THanks DaveF,

That's exactly what Valik was mentioning in a discussion with JON. Some applications don't deliver output until they stopped. :P

I cannot remember if he was looking for a solution for those.

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

Now it even works with the MS Powershell.

ptrex

Hi Ptrex- Can you show an example with PowerShell? Here's the PowerShell line that I'd like to collect inside of AutoIT:

Get-WmiObject win32_SystemEnclosure | select serialnumber
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

And it works on a remote computer as well:

Dim $pid, $ourOutput
     
; Open with connections to STDIN and STDOUT
     $pid = Run("c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe Get-WmiObject -computer mycomputer win32_SystemEnclosure | select serialnumber", @SystemDir, @SW_HIDE, 3)
     StdinWrite($pid, @CRLF)
; Call with no string param to close STDIN
     StdinWrite($pid)
     
     While 1
         $ourOutput &= StdoutRead($pid)
         If @error Then ExitLoop
     WEnd
         
     MsgBox(0, "", $ourOutput)
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

@Jefhal

This is a working example that needs more refining.

#include <Constants.au3>

$Cmd = '$colItems = get-wmiobject -class "Win32_NetworkClient" -namespace "root\CIMV2" `'&@CR& _
       '-computername "." '&@CR& _
       'foreach ($objItem in $colItems)'&@CR& _
       '{write-host "Caption: " $objItem.Caption'&@CR& _
       'write-host "Description: " $objItem.Description'&@CR& _
       'write-host "Installation Date: " $objItem.InstallDate'&@CR& _
       '}'

; -noexit -noprofile -command help about_automatic_variables"

$PowerShell = Run('PowerShell.exe -command '&$Cmd, "", @SW_HIDE , _
                $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD)

StdinWrite($PowerShell,@CRLF) 
StdinWrite($PowerShell)

While 1
    $line = StdoutRead($PowerShell)
    If @error Then ExitLoop
    ;If $line <> "" Then
    ConsoleWrite($line)
    ;EndIf
Wend

While 1
    $line = StderrRead($PowerShell)
    If @error Then ExitLoop
    ConsoleWrite( "STDERR read: "& $line& @CR)
Wend

If you have something going post some examples in the Example Scripts section.

regards,

ptrex

Link to comment
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
 Share

  • Recently Browsing   0 members

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