Sign in to follow this  
Followers 0
Comboku

_RunDOS - Keep CMD Open for second command?

8 posts in this topic

Hi Guys,

I want to go to a file path via "cd" that is stored in $Path. After that i would like to run the "custom.bat" with some options.

Problem with this programm is that i have to be in the directly to execute it. I can't simply do:

_RunDOS("cd " & $Path & "custom.bat Option1 Option2 file.file" )

that would lead to an error in the programm.

and 

_RunDOS("cd " & $Path)
_RunDOS("custom.bat Option1 Option2 file.file")

doesn't work either. Do you guys have an idea?

 

Thanks,

Comboku
 

Share this post


Link to post
Share on other sites



Use Run instead of _RunDOS which is just a wrapper for Run anyways. That way you can specify the working directory for the batch file to run in. Also, anything in the batch file could probably be converted to using just AutoIt and getting rid of the need for the batch file completely.


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

Thanks for the reply!

I have tried 

Run(@ComSpec,$Path, "custom.bat Option1 Option2 file.file")

without success. Is there maybe another way, or am i using the "run" command wrong?

 

Also i can't change the programm since it's fairly complex and was not programmed by me. ;)

Share this post


Link to post
Share on other sites
    Run(@ComSpec,$Path,@SW_HIDE)
    Sleep(1000)
    Send('create.bat Option1 file.file')
    send ("{enter}")

maybe this helps understanding what i try to do... This code would work exept for the @SW_HIDE.

 

Share this post


Link to post
Share on other sites
Run(@ComSpec & $Path & "custom.bat Option1 Option2 file.file", $Path) ; this will work if $path ends in \ if it doesn't add the backslash in the line before custom.bat
; or
ShellExecute($Path & "custom.bat", "Option1 Option2 file.file", $Path) ; this will work if $path ends in \ if it doesn't add the backslash in the line before custom.bat

 


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
44 minutes ago, Comboku said:

Hi Guys,

I want to go to a file path via "cd" that is stored in $Path. After that i would like to run the "custom.bat" with some options.

Problem with this programm is that i have to be in the directly to execute it. I can't simply do:

_RunDOS("cd " & $Path & "custom.bat Option1 Option2 file.file" )

 

Keep in mind the _RunDOS() execute the command prompt in a hidden window.  Also _RunDOS() open a single command prompt window, if you want to execute two batch file commands you need to add a double &&

$Path = "C:\Temp"
_RunDos("cd " & $Path & " && custom.bat Option1 Option2 file.file")

Using Run() or RunWait() function as BrewManNH suggested is even easier

Run(@ComSpec & " /C custom.bat Option1 Option2 file.file", $Path, @SW_SHOW)

RunWait(@ComSpec & " /C custom.bat Option1 Option2 file.file", $Path, @SW_SHOW)

 


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Thanks so much guys! That helped alot! 

Only problem now is that the custom.bat is waiting for another keystroke to end, resulting in a loop after the "runwait" call. But i can maybe fix that in th custom.bat.

If you have any smart idea how to maybe automaticly close the cmd after, say 5 seconds, i would be realy happy :)

30 minutes ago, Danny35d said:

 

Run(@ComSpec & " /C custom.bat Option1 Option2 file.file", $Path, @SW_SHOW)

RunWait(@ComSpec & " /C custom.bat Option1 Option2 file.file", $Path, @SW_SHOW)

 

 

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  
Followers 0