Jump to content

Can't get an external program to run from a different directory as the script, but use the script's directory as it's working dir.


Recommended Posts

The subject summarizes it all.

There's an external app that I'm running that, when run with Run($app_path,@ScriptDir), it just runs with the directory that it was extracted to as it's working directory.

Any way to solve this? I can't pass the problem to the running app, it's actually a suite of different apps for which we have no way of reprogramming, it's a legacy system that for now can't be upgraded.

Thanks for the ideas!

Link to comment
Share on other sites

workaround: call a batch file that CD's to the working directory and then let that batch file call the exe.

note: this is a workaround, but of course a solution is preferred. i encountered a similar issue once, but didn't have the time to put in it. i'll get to it.. sometime.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

workaround: call a batch file that CD's to the working directory and then let that batch file call the exe.

note: this is a workaround, but of course a solution is preferred. i encountered a similar issue once, but didn't have the time to put in it. i'll get to it.. sometime.

Hi!

I tried doing these 2 things:

1) Running a bat at @scriptdir, which goes to the folder where the app is located with "cd" and runs it

2) Running a bat at @scriptdir, which calls the exe directly from the working dir by using it's full path.

With both I received the same result.

Here's a sample script for the code I'm using:

$app = @TempDir & "\app.exe"
FileInstall("app.exe",$app)
ShellExecute("launcher.bat",@WorkingDir)

I also tried with Run, RunWait and ShellExecuteWait.

 

This is the bat, the 2 versions:

cd %temp%
app.exe
%temp%\app.exe
Link to comment
Share on other sites

check your cd %temp% properly:

it may require double-quotes if there are spaces in it:

cd "%temp%"

it may be on another drive:

C:

cd "%temp%"

add a pause and examine the prompt to make sure you are in the right place:

C:

cd "%temp%"

pause
app.exe

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

 

check your cd %temp% properly:

it may require double-quotes if there are spaces in it:

cd "%temp%"

it may be on another drive:

C:

cd "%temp%"

add a pause and examine the prompt to make sure you are in the right place:

C:

cd "%temp%"

pause
app.exe

 

Hi!

Yes, I did.

I added a pause before it changes directory and after it runs, it's running perfectly, so the bat is not the issue.

Link to comment
Share on other sites

sorry for late reply. first, Run() works as expected with a simple test. take this:

Run('cmd.exe',@ScriptDir)

compile it, put the exe anywhere in your drive, call it from anywhere else, and see that the prompt is the path where you put the exe.

(tested on AutoIt 3.3.8.1)

now, please describe your issue better, because i think you may be trying to solve the incorrect problem. if you manage to set the working directory successfully, then what exactly is the problem?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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...