[1.1.4] Windows: Working dir not set

Bug #1813494 reported by spikedboy on 2019-01-27
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sikuli
High
RaiMan

Bug Description

With an App object created with the path to an executable.

When doing app.open().

The working directory for the process is not set, hence causing some processes to be unable to run or function properly.

RaiMan (raimund-hocke) wrote :

Please give me an example and your expectation.

Changed in sikuli:
status: New → In Progress
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.4
spikedboy (spikedboy) wrote :

When you do:

App app = new App("C:\\Path\\to\\runnable.exe");
app.open();

This triggers a cmd execution to Windows, like:

cmd /C start "" /B "C:\Path\to\runnable.exe"

Problem is this cmd command seems to be run inside a default directory or inheriting java's user dir, not sure exactly. As in, the current working dir for the commandline. Which one would change with the cd command.

Nevertheless what I would expect is the command to be run inside of the folder where the executable is or optionally specify where the current dir should be for the command.

One could do this using the processBuilder.directory(File file) method, as I see you are using the ProcessBuilder class in the org.sikuli.util.ProcessRunner class.

It is important because some processes use relative paths to their working directory. I've encountered some that just plain refuse to run without the current working directory being set in a particular way.

I hope my explanation is helpful.

Cheers!

RaiMan (raimund-hocke) wrote :

Thanks for the detailed explanation - appreciated and understood.

The solution would be to add the /D parameter to the issued start command, which sets the starting directory.

To activate this setting, I will add

app.setWorkingDir("some directory")

which in turn will serve the start parameter /D.

To save typing of duplicate info the sequence:
app = new App("./runnable.exe").setWorkingDir("C:\Path\to")
app.open()
would expect the runnable in the given working dir and check that at time of open().

Without the ./ (or .\\) marker, the given program is found according to the Windows rules.

Since I do not have access to a Window system (developing on Mac ;-) during the week, you would do me a favour, if you could test the command

cmd /C start "" /B /D "C:\Path\to" "C:\Path\to\runnable.exe"

and confirm, that your program then is running in the working dir.

spikedboy (spikedboy) wrote :

Can confirm, that worked wonderfully. Process ran as expected.

RaiMan (raimund-hocke) wrote :

I added the feature this way:

App app = new App("C:\\Path\\to\\runnable.exe");
app.setWorkDir();
app.open();

which sets the working directory to the absolute path of the directory the runnable is located.

If you want to specify a different or separate working dir:
App app = new App("C:\\Path\\to\\runnable.exe");
app.setWorkDir("C:\\Path\\to\\someOtherDir");
app.open();

I would appreciate your tests (could not yet test it on Windows ;-)

fixed as 2019-02-03 build #190

Changed in sikuli:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers