Jump to content

Recommended Posts

Posted (edited)
;----------- here it works!!!

$net = Run(@ComSpec & " /c netstat -an",'',@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

Return_Output($net)

;---------------------------------------------------------------

$xcopy = Run(@ComSpec & " /c xcopy c:\mytest d:\mytest2 /Y /H /E /C",'',@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

Return_Output($xcopy)


Func Return_Output($job)

    Dim $_StderrRead='', $_StdoutRead='', $_StdReadAll=''

    While ProcessExists ( $job )

        $_StderrRead = StderrRead ( $job )
        If @error Then ExitLoop

        If Not @error And $_StderrRead <> '' Then
            ConsoleWrite ( "STDERR read : " & $_StderrRead & @CRLF )
            $_StdReadAll = $_StdReadAll & $_StderrRead & @CRLF
        EndIf

        $_StdoutRead = StdoutRead ( $job )
        If Not @error And $_StdoutRead <> '' Then
            ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @CRLF )
            $_StdReadAll = $_StdReadAll & $_StdoutRead & @CRLF
        EndIf

    Wend

    ProcessClose($job)

    Return ($_StdReadAll)

EndFunc

 

I would like to read the output of xcopy, can anyone tell me what i am wrong with in my script, thanks!! SO windows 10 64 

Edited by rootx
Posted

 

this is really not applicable !! The solution is to run the script with Admin permissions (#RequireAdmin)!!! Is there any way to make it work without it?

Posted (edited)

@error only really works for the command immediately preceding it, so the following isn't going to work well.

$_StderrRead = StderrRead ( $job )
        If @error Then ExitLoop

        If Not @error And $_StderrRead <> '' Then

How it should be written is as follows.

$_StderrRead = StderrRead ( $job )
        If @error Then
            ExitLoop
        ElseIf $_StderrRead <> '' Then

If it is an error then by definition it isn't NOT an error, so will exit the loop and never get to that statement.

Haven't run your code, so not sure if that alone fixes things.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

This is working for me without #RequireAdmin :

#include <Constants.au3>

$net = Run(@ComSpec & " /c netstat -an",'',@SW_HIDE,$STDERR_MERGED)
ConsoleWrite (Return_Output($net) & @CRLF)

;---------------------------------------------------------------

$xcopy = Run(@ComSpec & ' /C xcopy c:\Apps\Temp\*.* c:\Apps\Temp2 /Y /H /E /C /I','',@SW_HIDE, $STDERR_MERGED+$STDIN_CHILD)
ConsoleWrite (Return_Output($xcopy) & @CRLF)

Func Return_Output($job)
  ProcessWaitClose ($job)
  Return StdoutRead ($job)
EndFunc

By the way, your Return_Output is unnecessary too complex. 

Posted
4 hours ago, TheSaint said:

@error only really works for the command immediately preceding it, so the following isn't going to work well.

Some clarification: I think @error is only reset after calling another function, not after every command (statement). So the first code example should also work in theory, however I do agree that it is bad style to use @error like that.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

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...