Elishac Posted March 16, 2010 Share Posted March 16, 2010 Hello, I'm trying to open a .exe file. The autoit source I created couldn't be any simpler (only 1 line) : Run("C:\documents and settings\elishac\Desktop\myprogram.exe") The result is that myprogram.exe flashes for 0.1 second and then disappears. This is not what I want. If I type the very same path in windows->run, it works. If I type Run("C:\program files\mozilla\firefox.exe") instead, it works as well. So I really don't understand why it wouldn't work for myprogram.exe. I don't know if this is relevant, but myprogram.exe was self-made using the sdl librairy. Can you help me to fix this issue ? Thanks. Link to comment Share on other sites More sharing options...
omikron48 Posted March 16, 2010 Share Posted March 16, 2010 Define a working folder when you use Run. By default, programs called by Run execute from the directory the script is located. Some programs need to run in their current location to work properly. Link to comment Share on other sites More sharing options...
MHz Posted March 16, 2010 Share Posted March 16, 2010 By not specifying a working parameter for Run(), then Run() will inherit the current working directory. This inheritance of working directory can be at the initial running of your script if you pass a working directory via a shortcut, CMD prompt etc. The AutoIt functions of FileChangeDir() and FileOpenDialog() can change the working directory of your script so be aware of that. Starting your script with a mouse click will usually make your script inherit the directory that your script is located within the explorer shell. Installed programs usually use working directories passed by the shortcuts that you click on. Look into the properties of the shortcut to find the working directory (perhaps listed as "Start In" or something similar) that your script may need. Link to comment Share on other sites More sharing options...
99ojo Posted March 16, 2010 Share Posted March 16, 2010 Hi, try: Run("'C:\documents and settings\elishac\Desktop\myprogram.exe'") instead. ;-)) Stefan Link to comment Share on other sites More sharing options...
electrico Posted March 16, 2010 Share Posted March 16, 2010 Hi, please use the macro @Desktop insted of full path to your desktop. Also you can manipulate with ShellExecute() instead of Run(), or ever _RunDOS if the program is console.. _RunDOS func. require #include <process.au3>. elect. Link to comment Share on other sites More sharing options...
Elishac Posted March 16, 2010 Author Share Posted March 16, 2010 Hello, thanks for all these answers. I've tried quite a lot of different things that you mentionned, including : Run("'C:\documents and settings\elishac\Desktop\myprogram.exe'") Run("myprogram.exe", "C:\documents and settings\elishac\Desktop\") Run("myprogram.exe", @DesktopDir) Run(@DesktopDir & "myprogram.exe") and some others (I've tried so many I don't even remember). The only one that worked is FileChangeDir(@DesktopDir) Run("myprogram.exe") I don't understand why this is, and in particular I don't understand why it would work for Run("C:\program files\mozilla\firefox.exe") and not for Run("C:\documents and settings\elishac\Desktop\myprogram.exe"). I'm executing the .au3 from a folder that is located on the desktop. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 16, 2010 Share Posted March 16, 2010 How about Run(@DesktopDir & "\myprogram.exe")? Notice the backslash in the string. @Desktopdir doesn't include a following backslash. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
MHz Posted March 17, 2010 Share Posted March 17, 2010 Hello, thanks for all these answers. I've tried quite a lot of different things that you mentionned, including : Run("'C:\documents and settings\elishac\Desktop\myprogram.exe'") Run("myprogram.exe", "C:\documents and settings\elishac\Desktop\") Run("myprogram.exe", @DesktopDir) Run(@DesktopDir & "myprogram.exe") and some others (I've tried so many I don't even remember). Possible issues listed below: So it seems that the attempts without a correct working directory fails for your app. The app possibly relies on dependant files within the same directory as the executable.Not specifying a path to the executable fails as your Au3 file is in another directory so it fails to find the executable.Enclose qoutes around a path if whitespace may exist else it may fail. i.e. '"path\to\exe"'The only one that worked is FileChangeDir(@DesktopDir) Run("myprogram.exe") I don't understand why this is, and in particular I don't understand why it would work for Run("C:\program files\mozilla\firefox.exe") and not for Run("C:\documents and settings\elishac\Desktop\myprogram.exe"). I'm executing the .au3 from a folder that is located on the desktop. This as you say works (added comments for reasoning) ; This changes the working directory of the whole script FileChangeDir(@DesktopDir) ; myprogram.exe will inherit the working directory @DesktopDir Run("myprogram.exe") If setting the working directory worked fine then so should the below. ; Only myprogram.exe will inherit the working directory @DesktopDir Run('"' & @DesktopDir & '\myprogram.exe"', @DesktopDir) The later example means the only the run executable has a working directory set rather then the whole script as the previous example above does using FileChangeDir(). As for firefox.exe, perhaps it can run without the files located within it's own directory. The reason can be that it does not fail as to not requiring file dependencies. Firefox may not see it's global plugins etc. if the correct working directory is not used though this is but just assumption at this moment as I have not looked at firefoxes behavior. Link to comment Share on other sites More sharing options...
Elishac Posted March 19, 2010 Author Share Posted March 19, 2010 Ok, thanks. Link to comment Share on other sites More sharing options...
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