Jump to content

run function not working (beginner)


Recommended Posts

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

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...