Sign in to follow this  
Followers 0
Elishac

run function not working (beginner)

9 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

:(

Share this post


Link to post
Share on other sites

Hi,

try:

Run("'C:\documents and settings\elishac\Desktop\myprogram.exe'")

instead.

;-))

Stefan

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Ok, thanks.

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