Jump to content

command-prompt gives response but autoit doesn't


 Share

Recommended Posts

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

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

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

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

Link to comment
Share on other sites

 

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

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

×
×
  • Create New...