LittleVaaty / VDesk

Launch programs on new virtual desktops.
GNU General Public License v3.0
37 stars 0 forks source link

Running: Set correct current working directory (and potentially allow relative path running) #10

Closed DoS007 closed 6 months ago

DoS007 commented 6 months ago

VDesk started programs should behave in regard of workings directory like started without vdesk:

"Normal" Behavior

For testing I have a small basedir\testdir\test.bat file which i run in a cmd in basedir\contains:

@echo off
echo %cd%
echo:
echo %~dp0
echo:
echo %~dpnx0
echo:
echo %~f0
echo:
echo %PATH%

This means:

%cd% refers to the current working directory (variable) %~dp0 refers to the full path to the batch file's directory (static) %~dpnx0 and %~f0 both refer to the full path to the batch directory and file name (static).

(Source: Stackoverflow)

When I run above file in cmd without vdesk no matter if i run relative (.\testdir\test.bat) or absolute ("C:\...\basedir\testdir\test.bat" - exact path not copied here for privacy), I get:

C:...\basedir C:...\basedir\testdir\ C:...\basedir\testdir\test.bat C:...\basedir\testdir\test.bat (and the path variable; empty lines not copied)

Current vdesk behavior

Now starting the batch in the same basedir\ via vdesk: vdesk run -o 1 "C:\...\basedir\testdir\test.bat" (absolute - exakt path not copied here for privacy).

C:...\basedir\testdir C:...\basedir\testdir\ C:...\basedir\testdir\test.bat C:...\basedir\testdir\test.bat

Relative running does not work (they all can not find the file):

vdesk run -o 1 ".\testdir\test.bat" or

vdesk run -o 1 .\testdir\test.bat or

vdesk run -o 1 "./testdir/test.bat" or

vdesk run -o 1 ./testdir/test.bat

Side note: Didn't list the PATH variable, but they seem to be the same.

Conclusion

The current working directory differs. So set the current working directory correctly.

This could be important for some programs and i had a problem where this could be the root cause (starting npx on a project).

And not so important: Allow relative path running.

Importance assessment

The first is important to fix, the second would just be nice but isn't essential.

And as always, thanks for your continuation of vdesk 😊.

DoS007 commented 6 months ago

Relating working directory: This may be the relating line . So the important line to change is here: startInfo.WorkingDirectory = Path.GetDirectoryName(command);. This should be set to the working directory of vdesk itself.

Could you change that? I would test the result then with my test.bat above.

LittleVaaty commented 6 months ago

Now working directory of the process will be set to the current directory of vdesk. this also fix relative path. And i have added your script to my testscript folder.