Jump to content
Sign in to follow this  
adamchapman

command-prompt gives response but autoit doesn't

Recommended Posts

adamchapman

I have installed the amazon command-line interface (http://aws.amazon.com/cli/)  and have it working in my cmd prompt dos window. For example, If I set the working directory  to C:UsersAdministrator and run the command below to upload a file to the S3 service:

 

aws s3 cp C:UsersAdministratorDesktopvpntimeout_text.txt s3:/clustertesting/vpntimeout_text.txt
 
I get the response:
 

upload: myfolder/file1.txt to s3:/mybucket/myfolder/file1.txt

 

 
However, trying to replicate the same command in Autoit with :
 
 
---------------------------------------------------------------------------
 
 
#include <Constants.au3>
 
;$ami_ID = "ami-1a0d912a"
;$n=1
 
; Command:
;$DOS = Run(@ComSpec & ' /k' & "aws ec2 run-instances " & $ami_ID &  " -n " & $n & " -k windows --instance-type t1.micro -g quicklaunch-1", "", "", $STDERR_CHILD + $STDOUT_CHILD)
 
 
 
 
$workingdir = "C:UsersAdministrator"
 
 
 
ConsoleWrite($DOS & @CRLF)
 
 
 
Local $output
While 1
    $line = StdoutRead($DOS)
    If @error Then ExitLoop
    ConsoleWrite($line)
Wend
 
 
ConsoleWrite($line & @CRLF)
ConsoleWrite("error = " & @error & @CRLF)
 
---------------------------------------------------------------------------
 
 
The dos window flashes up and a PID is returned in $DOS, and the error value is zero. However, unlike my command performed in the command prompt, the autoit version does not upload my file to S3 and does not print a response.
 
 
Does anyone see what I've done wrong in Autoit? From what I can tell me code should be performing the same command
 
sorry I haven't used the code editor for this post- it failed to work in two browsers o I ended up just pasting the raw text
Edited by adamchapman

Share this post


Link to post
Share on other sites
adamchapman

the editor on this forum is acting strange. 

my command prompt is :

 
aws s3 cp C:UsersAdministratorDesktopvpntimeout_text.txt s3:/clustertesting/vpntimeout_text.txt
 
and the response is:
 

upload: myfolder/file1.txt to s3:/mybucket/myfolder/file1.txt

but nothing comes back in autoit

Edited by adamchapman

Share this post


Link to post
Share on other sites
adamchapman

I can't figure out why the commands are blank in both  posts above, but I've made a batch file with the command in it...

 

aws s3 cp C:UsersAdministratorDesktopvpntimeout_text.txt s3:/clustertesting/vpntimeout_text.txt

 

If I double-click the batch file it runs perfectly. However even using ShellExecuteWait("mybatch.bat") doesn't work from autoit. Autoit Doesn't appear to wait for a response before closing the process. 

This is very odd 

Edited by adamchapman

Share this post


Link to post
Share on other sites
BrewManNH

Instead of posting new posts, edit your first post.

Also, use code tags around your script code, it's hard to read the way you have it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
sahsanu

 

I have installed the amazon command-line interface (http://aws.amazon.com/cli/)  and have it working in my cmd prompt dos window. For example, If I set the working directory  to C:UsersAdministrator and run the command below to upload a file to the S3 service:

aws s3 cp C:\Users\Administrator\Desktop\vpntimeout_text.txt s3:/clustertesting/vpntimeout_text.txt
I get the response:
upload: myfolder/file1.txt to s3:/mybucket/myfolder/file1.txt
However, trying to replicate the same command in Autoit with :
#include <Constants.au3>

;$ami_ID = "ami-1a0d912a"
;$n=1

; Command:
;$DOS = Run(@ComSpec & ' /k' & "aws ec2 run-instances " & $ami_ID &  " -n " & $n & " -k windows --instance-type t1.micro -g quicklaunch-1", "", "", $STDERR_CHILD + $STDOUT_CHILD)

$workingdir = "C:\Users\Administrator"

ConsoleWrite($DOS & @CRLF)

Local $output
While 1
    $line = StdoutRead($DOS)
    If @error Then ExitLoop
    ConsoleWrite($line)
Wend

ConsoleWrite($line & @CRLF)
ConsoleWrite("error = " & @error & @CRLF)
The dos window flashes up and a PID is returned in $DOS, and the error value is zero. However, unlike my command performed in the command prompt, the autoit version does not upload my file to S3 and does not print a response.
 
 
Does anyone see what I've done wrong in Autoit? From what I can tell me code should be performing the same command
 
sorry I haven't used the code editor for this post- it failed to work in two browsers o I ended up just pasting the raw text

 

 

It is really hard to understand your post ;-), first you show an aws s3 cp command and then you pasted a script used to execute another aws command....

1.- What is $workingdir variable for? You declared it but you don't use it at all.

2.- I don't know what the error is but the command is giving you some error... you can't see it because you are not reading StdErr output.

3.- It always show you 0 as result because it is catching this error from previous ConsoleWrite command.

So, try this and check what the error is:

#include <Constants.au3>

$ami_ID = "ami-1a0d912a"
$n=1

; Command:
$DOS = Run(@ComSpec & ' /k ' & "aws ec2 run-instances " & $ami_ID &  " -n " & $n & " -k windows --instance-type t1.micro -g quicklaunch-1", "", "", $STDERR_CHILD + $STDOUT_CHILD)

;$workingdir = "C:\Users\Administrator"

ConsoleWrite($DOS & @CRLF)
Local $output
While 1
    $line = StdoutRead($DOS)
    If @error Then ExitLoop
    ConsoleWrite($line)
Wend
While 1
    $line = StderrRead($DOS)
    If @error Then ExitLoop
    ConsoleWrite($line)
Wend

ConsoleWrite("error = " & @error & @CRLF)

Cheers,

sahsanu

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • rudi
      By rudi
      Hello,
      for a script to display PDF files I'd like to simply use the default program for PDF files, so I used "ShellExecute(<pdf-file-full-path>)" to open these files.
       
      The result for *SOME* of the workstations is, that the Adobe Reader starts up with asking for its language. (English/German). When starting AcroRd32.exe through "ShellExecute()", this "choose your language" dialog is showing up *ALWAYS*.
       
      Just to have mentioned it: Process Explorer is presenting this command line, it looks the same for both, PCs with and without that question "Choose Language? [English|German]"
      "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" --channel=4680.0.860715181 --type=renderer "\\pc0009\Y_DRV_H\Daten\TIF\08\32\G000110832_Freigegeben.idw.pdf"  
      The next approach I thought of was to use Foxit Portable (instead of Acrord32.exe), started from a Network Drive, but it's starting up ugly slowly...
      So I tried to "Run()" instead to "ShellExecute()" the Adobe Reader. Now the result looks more stange, the "select your language" dialog shows up every now and then, but not always for the Win7 installations affected.
       
      If I place a "msgbox()" just in front of the "run()" command, it seems never to show this "select your language" dialog.
      If I take out this MsgBox() the "select your language" dialog shows up sometimes.
      When I "ClipPut()" the run command prior the "Run()" and paste that one to a CMD box, then it seems to *NEVER* happen, that this "select your language" dialog shows up.
       
      "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" "\\pc0009\Y_DRV_H\Daten\TIF\08\32\G000110832_Freigegeben.idw.pdf" $AcroRead='"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"' $PDF='"Y:\Temp\DRV_H\Daten\TIF\33\85\153385_Freigegeben.dwg.pdf"' MsgBox(0,"Values",$AcroRead & @CRLF & $PDF,1) $MyCommand=$AcroRead & " " & $PDF ClipPut($MyCommand) Run($MyCommand)  
      It looks like, that this "--channel=... --type=renderer" parameters are always fact for the AcroRd32.exe instance, that is opening the PDF to be displayed. The Instance opening the "PDF Display GUI" seems to always be a child process of another AcroRd32.exe process.
       
      Any clue, what's going on "backstage" here? How to avoid this "Choose your language" dialog? Or maybe someone can mention a different "portable" PDF viewer, I could use for this purpose?  
      Any suggestions appreciated, regards, Rudi.
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      With this script you can print Unicode text in the CMD screen
      the script is  easy to use
      just you  write the text that contains Unicode in the first input
      and the script automatically reflect the code in the second input
       you can copy the text to the clipboard
      or you can try printing the text in the CMD window
      I apologize to everyone for colors and shape if not appropriate
      I'm a blind man and I do not see
      Thank you for your understanding
      Greetings to all of youCmdUtM.au3
    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • Kevin Finnegan
      By Kevin Finnegan
      Hi all,
      Long time lurker and now forum poster! I'm writing a relatively simple backup script for my firm that automates the copy, compression and organization of Leaver's data on one of our secured NAS systems. I personally found the best method to do this so far was to use 7zG.exe (GUI version of 7Zip which can use command-line too) and it functions quite well!
      I would like to retrieve more info on whether any warnings or errors happen in 7Zip during the backup, but I can't quite get my head around the syntax and switches for reading out, it seems any adjustment I make to the RunWait call's string seems to break the backup or give unexpected repercussions! Hopefully its something silly I'm doing as I don't code very often.
      Here is the working version:
      ; Compress the directories one by one in the zip using the listfile.... Local $iPID = RunWait(@ScriptDir & "\bin\7zG.exe a -mx" & $compressionQuality & " -v" & $compressSplitFileSize & " -wc:\temp " _ & $backupToLocation & "\" & $userDirectory & ".7z @bin\listfile.txt -x@bin\excludefile.txt", "", @SW_SHOWDEFAULT, $STDOUT_CHILD) Ultimately I would love to switch entirely to 7za.exe (standalone) so that I can read the progress percentage, current file being uploaded and any warnings or errors could be processed and output to the AutoIT script's GUI I've created rather than jumping in and out of two applications per se.
       
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×