jben Posted April 3, 2008 Posted April 3, 2008 (edited) Hi everyone. Got a problem I'm trying to work out how to run a batch file in my AutoIT script. The batch file cmd appears but doesn't actually do anything. Is there some different command i've got to use other than shellexecute. Thanks and yes the batch file works if I manually click it myself. Edited April 3, 2008 by jben
DarkMatter Posted April 3, 2008 Posted April 3, 2008 (edited) ShellExecute should work. Have you tried Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\test.bat" & Chr(34), @ScriptDir) Edited April 3, 2008 by DarkMatter [sub]Quantum mechanics: The dreams stuff is made of[/sub]
Monamo Posted April 3, 2008 Posted April 3, 2008 Hi everyone. Got a problem I'm trying to work out how to run a batch file in my AutoIT script. The batch file cmd appears but doesn't actually do anything. Is there some different command i've got to use other than shellexecute. Thanks and yes the batch file works if I manually click it myself. Try using the Run() command instead of ShellExecute() To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)Quick example: $cmdPath = Chr(34) &"C:\Documents and Settings\User\Desktop\test.cmd" &Chr(34) Run(@ComSpec & " /c " & $cmdPath, "") - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
jben Posted April 3, 2008 Author Posted April 3, 2008 Cheers I will try that. One thing I am wondering though. Is it possible to put the script dir in the code. Because I will be running it from the same folder. thanks
Monamo Posted April 3, 2008 Posted April 3, 2008 Cheers I will try that. One thing I am wondering though. Is it possible to put the script dir in the code. Because I will be running it from the same folder.thanksYep, see DarkMatter's example above regarding placing the batch file in the Script directory. - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
jben Posted April 3, 2008 Author Posted April 3, 2008 (edited) just tried thisRun(@ComSpec & " /c " & Chr(34) & @ScriptDir & "Software\test.bat" & Chr(34), @ScriptDir)and I get a cmd box appear for a split second but nothing happens. Not sure why?To explain in more detail I'm trying to run something called devcon.exe http://support.microsoft.com/kb/311272Basically I have the devcon.exe and the batch file within my Software directory. Then devcon scans for hardware changes. But runs through a batch file. Therefore I'm trying to run the batch file within AutoIT but its having none of it. Edited April 3, 2008 by jben
MadBoy Posted April 3, 2008 Posted April 3, 2008 just tried thisRun(@ComSpec & " /c " & Chr(34) & @ScriptDir & "Software\test.bat" & Chr(34), @ScriptDir)and I get a cmd box appear for a split second but nothing happens. Not sure why?To explain in more detail I'm trying to run something called devcon.exe http://support.microsoft.com/kb/311272Basically I have the devcon.exe and the batch file within my Software directory. Then devcon scans for hardware changes. But runs through a batch file. Therefore I'm trying to run the batch file within AutoIT but its having none of it.What you actually want to achieve using devcon? I've wrote soft that does some things using devcon maybe you could use it ? My little company: Evotec (PL version: Evotec)
MHz Posted April 3, 2008 Posted April 3, 2008 and I get a cmd box appear for a split second but nothing happens. Not sure why?Sounds OK. It will run the batch file and close. Try the /k switch. Run(@ComSpec & ' /k test.bat')
Danny35d Posted April 3, 2008 Posted April 3, 2008 just tried thisRun(@ComSpec & " /c " & Chr(34) & @ScriptDir & "Software\test.bat" & Chr(34), @ScriptDir)and I get a cmd box appear for a split second but nothing happens. Not sure why?You are missing a back slash between the " and software.Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\Software\test.bat" & Chr(34), @ScriptDir) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Monamo Posted April 3, 2008 Posted April 3, 2008 (edited) just tried this Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "Software\test.bat" & Chr(34), @ScriptDir) and I get a cmd box appear for a split second but nothing happens. Not sure why? To explain in more detail I'm trying to run something called devcon.exe http://support.microsoft.com/kb/311272 Basically I have the devcon.exe and the batch file within my Software directory. Then devcon scans for hardware changes. But runs through a batch file. Therefore I'm trying to run the batch file within AutoIT but its having none of it.At first glance, it looks like you're just missing a trailing slash. Your run line should have a slash after @ScriptDir: Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\Software\test.bat" & Chr(34), @ScriptDir) Edited April 3, 2008 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
DarkMatter Posted April 3, 2008 Posted April 3, 2008 What version of devcon are you using? Newer version of devcon do not have a "scan" function, only "rescan" [sub]Quantum mechanics: The dreams stuff is made of[/sub]
jben Posted April 3, 2008 Author Posted April 3, 2008 (edited) Scan works because I can run it manually if i click the batch file myself. UPDATE Sorry i'm actually using devcon rescan Edited April 3, 2008 by jben
MadBoy Posted April 3, 2008 Posted April 3, 2008 What version of devcon are you using? Newer version of devcon do not have a "scan" function, only "rescan"$devcon = @TempDir & "\devcon32.exe"$devcon_rescan = RunWait(@ComSpec & " /c " & $devcon & " rescan", '', @SW_HIDE)That's how i run it. Althought that call can be done with internal AutoIt capabilities. My little company: Evotec (PL version: Evotec)
Danny35d Posted April 3, 2008 Posted April 3, 2008 Still not having any joy even with that code.Run(@ComSpec & " /c " & Chr(34) & @ScriptDir & "\Software\test.bat" & Chr(34), @ScriptDir)I'm assuming you try the above code line. If that is the case change the /c for /k so the command windows stay open and you can read any error message. AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
digibuddha Posted April 3, 2008 Posted April 3, 2008 (edited) Hey Man, I run batch files like this all the time... RunWait("Driveletter\path\anyname.bat") Now one thing I have noticed with AutoIT is that when it calls CMD.exe it calls it from %windir%\system32, yes I know thats where its at, which caused the DOS prompt to be C:\%windir%\System32 , but I had a problem with a script running from there, soooo... In my batch I ran it like this: cd\ cls path* anyname.bat That seemed to clear up the issues like your having of it not doing anything, or failing. Maybe this will help. Edited April 3, 2008 by digibuddha
jben Posted April 3, 2008 Author Posted April 3, 2008 Can you show me how you would create your batch file?. I'm really getting nowhere fast with this one.
jben Posted April 3, 2008 Author Posted April 3, 2008 (edited) Just tried this Run(@ComSpec & " /k " & Chr(34) & @ScriptDir & "\Software\test.bat" & Chr(34), @ScriptDir) now I get something in the cmd saying 'c:\documents' is not recognized as an internal command Edited April 3, 2008 by jben
digibuddha Posted April 3, 2008 Posted April 3, 2008 (edited) My batch file is like the above: CD\ cls cd path* batch to run That error you are getting is because DOS can't read the space in the path, put quotes around your path like this: "C:\Documents and Settings\rest of path\anyname.bat" Example of one of my batch files: cd\ cd down* cd task* inst_task.cmd pause Edited April 3, 2008 by digibuddha
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now