Jump to content

Recommended Posts

Posted

I'm trying to run a command line to create a network shared folder and make sure that I don't get an access denied error. When I use the following:

$pid = RunWait('"' & @ComSpec & '" /c net share SharedFolder="C:\TEST" /grant:everyone,FULL', '', @SW_HIDE, $STDOUT_CHILD)
    $sOutput = StdoutRead($pid)
    MsgBox(0, "", $sOutput)

It runs but a blank msgbox shows up and the following is written to the SCITE console:

System error 5 has occurred.

Access is denied.

Why isn't this being captured? Is there any way of telling if the command executed correctly?

Posted (edited)

Try this:
 

#RequireAdmin

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

_Example()
Func _Example()
    Local $iPID = RunWait('"' & @ComSpec & '" /c net share SharedFolder="C:\TEST" /grant:everyone,FULL', '', @SW_HIDE, $STDOUT_CHILD)
    Local $sOutput = ''
    
    While 1
        $sOutput &= StdoutRead($iPID)
        ; Exit the loop if the process closes or StdoutRead returns an error.
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
    
EndFunc

 

Edited by mLipok
script fix :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

@mLipok: there is also a handle to $STDERR_CHILD needed.

#RequireAdmin
_Example()
Func _Example()
    Local $pid = RunWait('"' & @ComSpec & '" /c net share SharedFolder="C:\TEST" /grant:everyone,FULL', '', @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)

    While 1
        $sOutput = StdoutRead($iPID)
        ; Exit the loop if the process closes or StdoutRead returns an error.
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
    
EndFunc

 

Edited by AutoBert
Posted

look in my edit:  script fix :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I tried to run both examples, but I still get a blank msgbox. Its weird because I use the exact same function elsewhere and I get the readout, but it doesn't capture this error.

 

I actually really only care to capture the failures (if it is successful I just want the script to continue).

Posted

:oops:

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I assume it should have been Run instead of RunWait?

I tried just run and still I get the empty msgbox. I thought that maybe the stdoutread was getting wiped out when it errors so I even tried using a temp string but still no luck:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

_Example()
Func _Example()
    Local $pid = Run('"' & @ComSpec & '" /c net share SharedFolder="C:\TEST" /grant:everyone,FULL', '', @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
    local $sOutput
    While 1
        $sTemp = StdoutRead($pid)
        ; Exit the loop if the process closes or StdoutRead returns an error.
        If @error Then
            ExitLoop
        Else
            $sOutput=$sTemp
        EndIf
        Sleep(10)
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

EndFunc

 

  • Developers
Posted

There is a reason why we have these nice examples in the helpfile. ;)
You aren't reading the STDERR so don't get the error: Quick and dirty fix:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

_Example()
Func _Example()
    Local $pid = Run('"' & @ComSpec & '" /c net share SharedFolder="C:\TEST" /grant:everyone,FULL', '', @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
    local $sOutput
    While 1
        $sTemp = StdoutRead($pid)
        $sTemp &= StderrRead($pid)
        ; Exit the loop if the process closes or StdoutRead returns an error.
        If @error Then
            ExitLoop
        Else
            $sOutput&=$sTemp
        EndIf
        Sleep(10)
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

EndFunc

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Ohhhhhh that makes sense. I didn't realize they worked separately. That makes WAY more sense. Thanks @Jos!

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