Jump to content

Run Script But Hide The Command Window?


Recommended Posts

I have a script that runs a number of commands on separate lines. I run these commands by sending them to the command prompt window, but I want to be able to do it without the command prompt window coming up. I have tried using: Run(@AutoItExe & ' /AutoIt3ExecuteLine  "Send(''stuff'')"','', @SW_HIDE) 

But it still comes up. I am kind of at a loss right now, so any help would be appreciated. Thanks!

Link to comment
Share on other sites

  • Developers

Just run the commands directly without trying to type the commands from AutoIt3.
Which commands do you exactly want to run?

Jos

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

Link to comment
Share on other sites

Run('c:\windows\system32\cmd.exe', '')
Sleep(500)
Send('cd C:\Program Files (x86)\PrivateArk\PACLI\ {ENTER}')
Sleep(500)
Send('pacli init {ENTER}')
Sleep(500)
$Username = InputBox('USERNAME','ENTER YOUR USERNAME','','')

Send('pacli definefromfile VAULT="Vault Dev" parmfile="C:\Program Files (x86)\PrivateArk\PACLI\VaultDev.ini" {ENTER}')
Sleep(300)
Send('pacli default VAULT="Vault Dev" USER='& $Username &' FOLDER=Root {ENTER}')
Sleep(500)

Currently my code opens the command prompt and sends the commands that need to be run. I want it to execute the commands behind the scenes rather than have the user watch each one come through. PACLI is a third party executable which must be referenced in order to run the commands. Additionally, the commands need to run on separate lines.

 

I was looking at trying to use run() or runwait() to have make this happen, but have not had success. Any suggestions or am I going about this the wrong way? Thanks.

Link to comment
Share on other sites

  • Developers

Preferably you avoid trying to type text to an window. You could have a look at the STDOUT/STDIN functions to start cmd and PIPE the text straight into the shelled command to make it much more reliable.

Jos

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

Link to comment
Share on other sites

It would be greatly appreciated if you could  give me an example based off of the code above as to how to use stdin and stdout? I am finding a lot of very different information on how to go about doing so. Thanks.

Link to comment
Share on other sites

  • Moderators

@Chance1 did you look at the STDOUT/STDIN functions in the help file as suggested? They each contain just the example you're asking for.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thank you, I do have it working. One other question. In the example (and the way I do it), do you have to take all of the commands that you want to out put using StdinWrite(), close the stream, and then output? Is there a way that I can output the stream and then reuse the same stream? Or do I have to make another child/stream in order to output more commands?

Sorry if that is difficult to understand. I want to be able to send sections of the commands because I am going to be requesting information and I want to make sure that the information the user provided is correct before continuing with the script. Thanks!

Link to comment
Share on other sites

  • Developers

You can just perform everything you want to do and keep the STDXXX open as long as the program is running.
Why do you think you need to close it in between or am I misunderstanding?

Jos

 

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

Link to comment
Share on other sites

Well I want to be able to output the commands to cmd to check for user input errors (failed log in errors.) Doing so, I want to be able to propmt the user for a failed login, let them try again, and then continue on with the script. When I tried closing the stream, outputting, and then continuing to run using the same stream it wouldn't output the data after the first time I closed it.

Link to comment
Share on other sites

  • Developers

That is why I said not to close the STDXXX streams until you are done with the shelled program. You could simply interact with the user without closing the CMD right?

Jos

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

Link to comment
Share on other sites

I cannot interact no. Maybe my code is just wrong

StdinWrite($pPid, 'pacli logon USER = '& $Username &' PASSWORD = '& InputBox('PASSWORD', 'ENTER YOUR PASSWORD', '', '*') &@CRLF )

Local $data
While True
    $data &= StdoutRead($pPid)
    If @error Then
        MsgBox(0, "ERROR", "ERROR")
        ENDIf   
WEnd
MsgBox(0, "Report", $data)

If I have this code at the end of my script, with a close $pPid, it works and the output is shown. But, if it is in the middle of the code, nothing happens and the rest of the script does not run.

I am still in the testing phase, if I could catch the error I would send the user to a function and have them attempt to login again. The error I am trying to catch is if the password fails for the user.

Edited by Chance1
Link to comment
Share on other sites

  • Developers

Doesn't something like this work?:

While True
    $data &= StdoutRead($pPid)
    If @error Then
        MsgBox(0, "ERROR", "ERROR... program ended?")
    EndIf
    If StringInStr($Data,' whatever') Then
        $data = ""
        StdinWrite($pPid, 'pacli logon USER = '& $Username &' PASSWORD = '& InputBox('Invalid PASSWORD', 're-ENTER YOUR PASSWORD', '', '*') &@CRLF )
    EndIf
WEnd

Jos

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

Link to comment
Share on other sites

  • Developers

Isn't that error message appearing in the CMD box running the program and thus should be able to read by either StdoutRead() or StderrRead()?

Maybe the code needs adjusting to include reading the STDERR stream like:

While True
    $data &= StdoutRead($pPid)
    If @error Then
        MsgBox(0, "ERROR", "ERROR")
    EndIf
    $data &= StderrRead($pPid)
    ; Test here for invalid password text
    If StringInStr($Data,' whatever') Then
        $data = ""
        StdinWrite($pPid, 'pacli logon USER = '& $Username &' PASSWORD = '& InputBox('Invalid PASSWORD', 're-ENTER YOUR PASSWORD', '', '*') &@CRLF )
    EndIf
WEnd

Jos

Edited by Jos

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

Link to comment
Share on other sites

I am getting closer. With this code:

;for regular output
While True
    $data &= StdoutRead($pPid)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "STDOUT REPORT", $data)
$data = ''

;to catch errors
While True
    $data  &= StderrRead($pPid)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "STDERR REPORT", $data)

The first loop will output the stdout of the script and the second does grab the error messages thrown back. But, if i try to place that error loop in the middle of the code (while the stdin stream is still open), the script crashes. But If I have at the end of the code (after the stream is closed), it works just fine. The problem being, I want to catch the errors as they happen. So, I want that error loop in the code after the user inputs informationt that needs to be checked for errors.

Any idea why the script crashes if the loop is in the code while the stdin stream is still open? Thanks!

Link to comment
Share on other sites

  • Developers

Define a script crash? Does it show an error?
Also show what parameters you have now on the run statement to check whether you have that right.

Jos

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

Link to comment
Share on other sites

  • Developers
2 minutes ago, Chance1 said:

The script does not continue to run

So it ends without any error about a syntax or anything? Are you running it from SciTE  and no errors or exitcode are shown in the outputpane?

Can you show the total code that does this?

Jos

Edited by Jos

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

Link to comment
Share on other sites

Yes I am  running from SciTE

#include <Constants.au3>

Local $pPid = Run("C:\Windows\system32\cmd.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
Local $data = ''

StdinWrite($pPid, 'cd C:\Program Files (x86)\PrivateArk\PACLI\' & @CRLF )
StdinWrite($pPid, 'pacli init' & @CRLF)
StdinWrite($pPid, 'pacli definefromfile VAULT="Vault Dev" parmfile="C:\Program Files (x86)\PrivateArk\PACLI\VaultDev.ini"'& @CRLF)

$Username = InputBox('USERNAME','ENTER YOUR USERNAME','','')

StdinWrite($pPid, 'pacli default VAULT="Vault Dev" USER='& $Username &' FOLDER=Root' & @CRLF)
StdinWrite($pPid, 'pacli logon VAULT = "Vault Dev" USER = '& $Username &' PASSWORD = '& InputBox('PASSWORD', 'ENTER YOUR PASSWORD', '', '*') &@CRLF )


While True
    $data  &= StderrRead($pPid)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "STDERR REPORT AFTER LOGON", $data)

This is the begging, agter the while loop, the script doesn't continue. If that loop was not in there at all, the rest of the script will run perfectly. Maybe it is getting stuck in the loop?

All of the PACLI commands are correct and are not the issue. Again pacli is a third party executable where all of the commands must be on separate lines.

Edited by Chance1
Link to comment
Share on other sites

  • Developers

Ofcourse it stays in the loop as long as the process you are reading the STDERR stream of exists. So you need to read both STDOUT and STDERR and check the feedback of both for the TEXT you expect when it successfully runs or when the an ERROR occures. something like this:

While True
    $dataerr  &= StderrRead($pPid)
    If @error Then ExitLoop
    $dataout  &= StderrRead($pPid)
    If @error Then ExitLoop
    If stringinstr($dataerr, " text of login failed feedback") then
        $dataerr = ""
        ;;  prompt again for password and send to STDIN as shown before
    EndIf
    If stringinstr($dataout, " text of successful login feedback") then
        ExitLoop
    EndIf
    Sleep(25)
WEnd

Hope you understand the approach.

Jos

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

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