Run .exe from XoJo is not equal from Windows or from Visual Studio launch

Hi, I have a RefData.exe written in C ++.
The program works fine, but:

  1. if I run from Windows (double click on RequestData.exe), it writes the file named “AData.txt” in the SAME directory where RequestData.exe is located
  2. if I launch it from another application written in VisualStudio. writes the file named “AData.txt” in the SAME directory where the other application written in VisualStudio is located
  3. If I launch it from XoJo, no AData.txt !! No written!

I use this code in XoJo:
Dim f As FolderItem = _DirSpecialFolder.Child (“FOS-FlyOnSky”). Child (“RefData”). Child (“RequestData.exe”)
Var s As Shell
s = New Shell
s.Execute (f.NativePath)

And this is part of the RefData.exe code in C ++ where I write the AData.txt file
ofstream MyFile (“AData.txt”);
MyFile << “… my text …”;

Can you tell me how can do ?

My guess is that your C++ app is writing the file without specifying the path so that it is relying on the current working directory for its destination path.

The solution is to probably write the file specifying the full path or to find a way to set the cwd in the Xojo shell.

1 Like

Xojo shell always executes in the root directory C:, which is often read only for applications.

To go around this, you need to change directory before you launch your program.

This needs to be done in the same shell.execute, like so:

    Dim f As FolderItem = _DirSpecialFolder.Child (“FOS-FlyOnSky”). Child (“RefData”). Child (“RequestData.exe”)
Var s As Shell
s = New Shell
s.Execute ("cd C:\Users\mitch\Downloads & " + f.NativePath)

In this example, I used the path to my downloads folder. You can put anything there. For instance SpecialFolder.Applications if you want the program to run in the same directory as your app.

Of course I solved it by working around:

string appData;
appData = getenv(“appdata”);
appData += “\ \FOS-FlyOnSky\ \AData.txt”;
MyFile << …

But I’d rather find a solution where XoJo behaves like VisualStudio, thus avoiding to insert “getenv” (and consequently _CRT_SECURE_NO_WARNINGS).

I’ll stay listening… :wink:

you could try SetCurrentDirectory if your c++ app run at the same process.
setcurrentdirectory