Jump to content

Why is my .bat (or command prompt window) closed so quicly when run with autoit?


Akshay07
 Share

Recommended Posts

Hello all,

I am using a .bat file to automize a FTP transfer. I know there is another way to do it using Inetget, but I do need to do the FTP transfer via command prompt.

The batch file consist of this:

ftp -s:ftp.txt

It points to a text file that contains this:

open <ftp IP address>
<username>
<password>
get <file to download>

When I run the .bat file manually, it works great.

When I call it wih Autoit using

Run ("ftp.bat")

I see the command prompt window being opened and then the first line sent ("open <ftp IP address>") but this happens very quickly and the command prompt window is closed almost immediately (and of course, there is not ftp transfer starting).

Any idea why?

Thanks

Link to comment
Share on other sites

ftp -s:ftp.txt
PAUSE

This is not a fix but if you put a pause cmd in your batch what error message (if any) does ftp.exe print to the command interface?

I have a feeling the batch cannot find the file ftp.txt.

or

RunWait(@COMSPEC &" /c your.bat > FTP.log",@SCRIPTDIR)

or

RunWait(@COMSPEC &" /k your.bat",@SCRIPTDIR)

You really don't need the batch you know, you could call ftp.exe directly with run().

$OUT = ""
$PID = Run("ftp.exe -s:"& @SCRIPTDIR &"\ftp.txt",@SCRIPTDIR,@SW_HIDE,7)
IF $PID THEN
 WHILE 1
 $OUT &= StdoutRead($PID)
 IF @ERROR THEN EXITLOOP
 WEND
ELSE
 $OUT = "Failed to execute program."
ENDIF
MsgBox(64,@SCRIPTNAME,$OUT)

Last bit untested

ah, You need to display the ascii progress bar, that is a piece of information that may have helped.

Edited by Mobius

wtfpl-badge-1.png

Link to comment
Share on other sites

I already tried to pause 30 seconds after the RUN instruction but it is the same.

I do need the command prompt, I need to see the progress in it (in the text file, there is a hash instruction missing), and not in any other progress bar.

I don't know if it makes any difference, but I try to run the .bat file in a specific folder:

Run ("C:\ftp\ftp.bat")

And when I pause the script and copy/paste the Run command I use in the script into Window key/run, it works fine

Link to comment
Share on other sites

For example: This is work for me:

RunWait("cmd.exe /c echo anonymous>>c:\pass.gif") ;login
RunWait("cmd.exe /c echo anonymous>>c:\pass.gif") ;pass
RunWait("cmd.exe /c echo cd public >>c:\pass.gif") ;cd public
RunWait("cmd.exe /c echo ls -lia>>c:\pass.gif")     ;listing
RunWait("cmd.exe /c ftp -v -s:c:\\pass.gif 212.38.114.20")   ;connecting to ftp host

after connection:

Пользователь (212.38.114.20:(none)):

ftp> cd public
public: No such file or directory.
ftp> ls -lia
total 12
     2 dr-xr-xr-x   6 0     5   512 May  8  2007 .
     2 dr-xr-xr-x   6 0     5   512 May  8  2007 ..
716800 dr-xr-xr-x   2 0     5   512 Jun 27  2003 bin
940800 d---------   2 0     5   512 Jun 27  2003 etc
492800 drwxr-xr-x  11 0     0   512 Jun 13  2009 incoming
336000 drwxr-xr-x  27 1004  0  1024 Nov 23 13:26 pub
ftp>
[size="5"] [/size]
Link to comment
Share on other sites

Hummm, your last answer is beyond my knowledge ;)

I tried this script from you (thanks a lot for it) and change one parameter to maximize the window

$OUT = ""
$PID = RunWait("ftp.exe -s:"& @SCRIPTDIR &"\Start_100MB_DL.txt",@SCRIPTDIR,@SW_MAXIMIZE,7)
IF $PID THEN
 WHILE 1
 $OUT &= StdoutRead($PID)
 IF @ERROR THEN EXITLOOP
 WEND
ELSE
 $OUT = "Failed to execute program."
ENDIF
MsgBox(64,@SCRIPTNAME,$OUT)

That looks very good, I am getting closer, but I have two more questions.

1/ Can I see the progress using "#" symbols? I really need to have this visible

2/ Will that piece of script allow the global script to keep on running without waiting the download to be completed? I forgot one important piece of information in my first message, I need to start the download AND proceed without waiting for the download to be completed

Thanks!

Edited by Akshay07
Link to comment
Share on other sites

4get about that code I posted, If you need to see the output in real time then reading the stdout buffer is not going to help you...

(plus there is a stupid error in it where RunWait should be Run, because the above will not work with Runwait. *Doh*)

Run(@comspec &' /k ftp.exe -s:"'& @SCRIPTDIR &'\Start_100MB_DL.txt"',@SCRIPTDIR,@SW_MAXIMIZE)

or

Run(@comspec &' /c ftp.exe -s:"'& @SCRIPTDIR &'\Start_100MB_DL.txt" && PAUSE',@SCRIPTDIR,@SW_MAXIMIZE)

Of course, all this would not be necessary if you created a cui executable out of your script with Aut2Exe or physically modified the subsystem of AutoIt3.exe, because ftp.exe's output would automatically go to your exe's stdout window (or an existing cmd shell when executed from one).

Edited by Mobius

wtfpl-badge-1.png

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