Jump to content
Sign in to follow this  
adamchapman

command-prompt gives response but autoit doesn't

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By WoodGrain
      Hi All,
      Trying to open windows explorer to a WebDav location and it's not working quite how I want, on the computers it is setup as a "network location" (as opposed to a "mapped drive", and this unfortunately can't be changed), the "Data" WebDav folder sits directly under "This PC" if that's an easier way to get to it. any suggestions as to what I can correct to get the 2nd example to work?
      ; This works, but I'm trying to avoid this as users normally see the URL style in the 2nd example below $folderToOpen = "\\mycompany.sharepoint.com@SSL\DavWWWRoot\Data" Run("Explorer.exe " & $folderToOpen) ; This does not work, it tries to open the WebDav url in the default web browser $folderToOpen = "https://mycompany.sharepoint.com/Data" Run("Explorer.exe " & $folderToOpen) ShellExecute also opens it in the default browser.
      Saw _WinAPI_ShellOpenFolderAndSelectItems but couldn't get the 2nd example to work.
      If I manually open Windows Explorer and paste in https://mycompany.sharepoint.com/Data it loads the WebDav directory without issue.
      If I have to use the pathing from the first example it is fine, just trying to give users a familiar experience.
      Thanks!
    • By nacerbaaziz
      hello autoit team
      is there any wey to check if any process run as admin or no?
      i mean e.g if i want to restart any process, now i have the ability to get the process path and commands line
      what i need is a wey to check if the process was runing as admin or no to restart it with the same state.
      here is the part that am using it to restart the process
      func _processRestart($i_pid, $s_ProcessPath) if not (ProcessExists($i_ProcessPid)) then return SetError(1, 0, -1) local $s_ProcessWorkDir = _WinAPI_GetProcessWorkingDirectory($i_ProcessPid) ProcessClose($i_ProcessPid) ProcessWaitClose($i_ProcessPid) ProcessWait(ShellExecute($i_pid,"", $s_ProcessWorkDir)) ProcessesGetList() return true endFunc thanks in advance
    • By cruisepandey
      Hi There ! 
      I have a script here : 
       
      ;Launch CMD
      Run("C:\Windows\System32\cmd.exe")
      sleep(2000)
      $cmdHandle = WinActivate("C:\Windows\System32\cmd.exe")
      Sleep(2000)
      ;Sending document
      ControlSend($cmdHandle, "", "", "ftp" & @CRLF)
      ControlSend($cmdHandle, "", "", "open" & @CRLF)
      Sleep(2000)
      ControlSend($cmdHandle, "", "", "first command" & @CRLF)
      Sleep(2000)
      ControlSend($cmdHandle, "", "", "second-coomand" & @CRLF)
       
      first-command and second-command I can't provide cause it's internal. I have complied this .au3 file into an exe and it does the work. But I need to invoke this with Java. Java code I have tried is : 
       
          ProcessBuilder pb = new ProcessBuilder("C:\\Users\\username\\eclipse-workspace\\Examples\\src\\com\\own\\examples\\etc.exe");
          pb.start();
          Thread.sleep(5000);
       
      Through java it just launches the cmd and nothing happens after that. Please help !!
    • By Chimp
      I'm trying to drive a command prompt by sending instructions via a NamedPipe.
      This way you can (should) be able to send commands to the command prompt and at the same time "view" the result in the same window.
      This is not allowed if you run a command prompt with "opt_flag" parameters (redirected streams) because this will disable StdOut on the cmd itself.
      This small (trivial) snippet works for the first command sent to the cmd, but further submissions will fail.
      Maybe the problem is in how I use the run () command to start a new cmd with the StdIn redirect from the NamedPipe. It seems that the generated cmd will close automatically after the first reception of the command via NamedPipe.
      suggestions on how to make it work are welcome
      thanks
      #include <NamedPipes.au3> #include <WinAPI.au3> ; Creates an instance of a named pipe Global $sPipeName = "\\.\pipe\pipename" Global $hPipe = _NamedPipes_CreateNamedPipe($sPipeName, 1, 1) MsgBox(0, "Debug", "Pipe created. Now open a CMD") ; run a cmd with only StdIn redirected (StdIn data incoming from a pipe) Global $hCMD = Run(@ComSpec & " /K cmd < " & $sPipeName & @CRLF, "c:\") ; ok? MsgBox(0, "Debug", "now Send a command to the cmd via a NamedPipe") _StdInPipeWrite("dir" & @CRLF) MsgBox(0, 'Debug', "further commands will fail" & @CRLF & "now send command 'dir c:\windows'") $sMessage = "Dir c:\windows" & @CRLF _StdInPipeWrite($sMessage) MsgBox(0, 'Debug', "send another command (will also fail)" & @CRLF & "now send command 'echo Hello'") _StdInPipeWrite("echo Hello" & @CRLF) MsgBox(0, "Debug", "end of test") ProcessClose($hCMD) Func _StdInPipeWrite($sMessage) ; =============================================================================================================================== ; This function writes a message to the pipe ; =============================================================================================================================== Local $iWritten, $iBuffer, $pBuffer, $tBuffer $iBuffer = StringLen($sMessage) + 1 $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tBuffer, "Text", $sMessage) If Not _WinAPI_WriteFile( _ $hPipe, _ ; ...... Handle to the file to be written $pBuffer, _ ; .... Pointer to the buffer containing the data to be written $iBuffer, _ ; .... Number of bytes to be written to the file $iWritten, _ ; ... The number of bytes written 0 _ ; ............ [optional] A $tagOVERLAPPED structure or a pointer to it ) Then ConsoleWrite("WriteMsg: _WinAPI_WriteFile failed" & @CRLF & _WinAPI_GetLastErrorMessage()) Else ConsoleWrite("WriteMsg: write OK" & @CRLF & _WinAPI_GetLastErrorMessage() & @CRLF) EndIf EndFunc ;==>_StdInPipeWrite  
    • By Burgs
      Greetings,
        I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines.  I was thinking of something similar to this:
      Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if $iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF) $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF, $SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF, $SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it.  I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer. 
      Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance.  Regards.
×
×
  • Create New...