APSIMInitiative / ApsimOnR

7 stars 8 forks source link

Path arguments on Windows #4

Closed codeandkey closed 9 months ago

codeandkey commented 2 years ago

When running CroptimizR on Windows 10 with a local R installation I run into the following error:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-C:/Program does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Error in apsimx_wrapper(model_options = model_options) : 
  C:/Program Files/APSIM2022.5.7042.0/bin/Models.dll is not executable or is not a apsimx executable !
In addition: Warning message:
In system(cmd, wait = TRUE, intern = TRUE) :
  running command 'dotnet C:/Program Files/APSIM2022.5.7042.0/bin/Models.dll /Version' had status 1
Execution halted

I think this might be due to the path being passed to system() being interpreted as multiple arguments when it contains spaces. Running the command dotnet "C:/Program Files/APSIM2022.5.7042.0/bin/Models.dll" /Version produces the expected output.

hol430 commented 2 years ago

Yes, that seems likely. As a workaround, you could try putting quotes around the path you're passing into the optimiser. E.g.

model_path <- '"C:/Program Files/APSIM2022.5.7042.0/bin/Models.dll"'
codeandkey commented 2 years ago

Unfortunately when adding quotes to the input path, the apsimx_wrapper checks if the quoted file exists here and fails early. I opened a PR #5 addressing this issue.