Skip to content

Commit

Permalink
Fixed some unix-specific bugs
Browse files Browse the repository at this point in the history
- Need to run Models.exe via mono, as it won't usually have execute
  permission set. e.g. `mono Models.exe $args`
- When running Models.exe, we need to quote some of the arguments,
  particularly the simulation name regex, otherwise shell expansion
  kicks in.
  • Loading branch information
Drew Holzworth committed Sep 1, 2020
1 parent 6d7c6c7 commit 4740249
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion R/apsimx_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ apsimx_wrapper <- function(model_options,
stop(paste("apsimx file doesn't exist !", apsimx_file))
}
cmd <- paste(apsimx_path, '/Version')
# On unix systems, need to run via mono.
if (.Platform$OS.type == 'unix') {
cmd <- paste('mono', cmd)
}
val <- system(cmd, wait = TRUE, intern = TRUE)

if ( !is.null(attr(val, "status"))) {
Expand Down Expand Up @@ -140,14 +144,23 @@ apsimx_wrapper <- function(model_options,

# Run apsimx ------------------------------------------------------------------
cmd <- paste(apsimx_path, file_to_run)
# on unix, need to run via mono.
if (.Platform$OS.type == 'unix') {
cmd <- paste('mono', cmd)
}
if (model_options$multi_process) cmd <- paste(cmd, '/MultiProcess')

if (!is.null(sit_var_dates_mask)) {
# This generates a regular expression of simulation names using alternation
# which will be passed to Models.exe to limit execution to the specified
# simulation names.
regex <- paste('(', paste(names(sit_var_dates_mask), collapse = ')|('), ')', sep = '')
cmd <- paste(cmd, ' /SimulationNameRegexPattern:', regex, sep = '')
if (.Platform$OS.type == 'unix') {
# on unix, need to escape the regex with quotes
cmd <- paste(cmd, " '/SimulationNameRegexPattern:", regex, "'", sep = '')
} else {
cmd <- paste(cmd, ' /SimulationNameRegexPattern:', regex, sep = '')
}
}

# Portable version for system call
Expand Down
4 changes: 4 additions & 0 deletions R/change_apsimx_param.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ change_apsimx_param <- function(exe, file_to_run, param_values) {

# Apply parameter changes to the model -----------------------------------------
cmd <- paste(exe, file_to_run, '/Edit', config_file)
if (.Platform$OS.type == 'unix') {
# need to run via mono on unices
cmd <- paste('mono', cmd)
}
#edit_file_stdout <- shell(cmd, translate = FALSE, intern = TRUE, mustWork = TRUE)
edit_file_stdout <- system(cmd, wait = TRUE, intern = TRUE)

Expand Down

0 comments on commit 4740249

Please sign in to comment.