Jump to content
Sign in to follow this  
power1power1

Combining Batch File Commands with Autoit Commands

Recommended Posts

power1power1

Hello, I was hoping to have a special autoit function to handle Windows batch file commands, something like this:

autoit commands

batchfile()

autoit commands

func batchfile()

    batch file commands

endfunc

Edited by power1power1

Share this post


Link to post
Share on other sites
Jfish

You can shellexecute a batch file within your function.

You can also run DOS console commands with Run ...

To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c"
Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
BrewManNH

Anything written for a batch file can be replaced with the appropriate AutoIt code.

  • Like 1

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
power1power1

Yes, thanks for the replies. Still, having such a special function would be nice.

Share this post


Link to post
Share on other sites
power1power1

Oh well, from functionality point of view, you can call a batch file from within an autoit script. However, what I was asking is a different way of doing it. You would insert your batch commands whithin a special function that would reside inside the autoit script. So, if you share your complied autoit code with others, you would provide them with the autoit file only, rather than the autoit file plus a bunch of related batch files. Any ways, it's wishful thinking, I guess.

Edited by power1power1

Share this post


Link to post
Share on other sites
BrewManNH

But why would you NEED the batch files or their commands, if the autoit script can do it, without resorting to using a command from another language?


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
power1power1

We can think of senarios that this would become handy: You would take your old batch files and just reuse the code, rather than rewriting them ...

Edited by power1power1

Share this post


Link to post
Share on other sites
Chimaera

I used to use a lot of batch stuff when i first started but i can assure you there is very little need for it as i have gradually moved my scripts into AutoIt and i would never go back as i have added functionality now which i couldn't get just with batch.

I still use robocopy and stuff like that but i control it from AutoIt nowadays and i have never had a situation where having batch code would be usefull.

Up to you of course

Share this post


Link to post
Share on other sites
Carlo84

You can do exactly what you want with the run function http://www.autoitscript.com/autoit3/docs/functions/Run.htm

Read the remarks

Also a tip to run several commands on one line you can seperate commands with the pipe character.

To get return valuess you have to use StdoutRead and StderrRead

Too much trouble then it's worth to re-invent the wheel

Edited by Djarlo

Share this post


Link to post
Share on other sites
power1power1

Thank you guys for the replies. I just want to emphasis again that the point was to prevent putting effort on the code rewriting/converting process, else you would just do the whole thing entirely in autoit.

Share this post


Link to post
Share on other sites
BrewManNH

If you're looking to directly run the batch file commands in an AutoIt script then your answer is, you can't. The 2 languages aren't compatible. If you want to run batch files then use batch files, you can always FileInstall them into a compiled script and delete when done with them. Or you can put the batch commands into the script, write a batch file when the script is run, run the batch file, and then delete it when done. See the _SelfDelete function in the example scripts forum to see how he did it with VBscript code, same concept.


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
power1power1

This would be a good workaround ... I guess one can create a temporary batch file in Windows temp directory, copy the text commands to the batch file, run the batch file and then delete the batch file when done.

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  

×