Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different file parsing by winexec and shell

    Using Stata/MP 16.0 on Mac with MacOS 10.14.5.

    I'm finding different behavior reading a space in the path of a file name by winexec and shell commands.

    I've got the following loop...

    Code:
    forvalues i = 1/`=`n'/`t'' {
        local s : word `i' of `seed'
        if "`i'" <= "`=(`n'/`t')-1'" local command winexec 
        if "`i'" == "`=`n'/`t''"     local command shell
        `command' `=c(sysdir_stata)'StataMP.app/Contents/MacOS/StataMP do "/Users/lde/Box/VA/Moral injury/mi_mi_19-07-22.do" `t' `b' `s' `i'
    }
    Basically, I'm calling new instances of Stata to execute some commands in a do file. The do file that runs in the new instances of Stata ultimately creates a new data file. I don't want the original instance to keep executing code until the new instances are done because the end result of each new instance is a new data file that is used in subsequent code. So, the final new instance of Stata needs to called using shell instead of winexec.

    However, winexec and shell seem to parse the path of the file name differently...The space in the file path isn't a problem for winexec but it causes a problem for shell. Here's what the new instance of Stata reads from the winexec command:

    Code:
    do "/Users/lde/Box/VA/Moral injury/mi_mi_19-07-22.do" 5 300 65485 6
    The code in the do file begins to execute as it should in the new instance of Stata. Here is what the new instance of Stata reads from the shell command along with the resulting error:

    Code:
    . do /Users/lde/Box/VA/Moral injury/mi_mi_19-07-22.do 5 300 76491 7 
    file /Users/lde/Box/VA/Moral.do not found
    r(601);
    Notice that the quotes around the file path and name are picked up by the winexec command but not the shell command. The end result is that the original instance of Stata thinks this final instance has completed its work and continues to the subsequent code that looks for the existing files which don't exist yet.

    I know a simple solution to this problem would be to rename the directory whose name has a space in it to not include a space but I tend to use spaces in directory names a bunch. I'm wondering why these commands treat the space differently. Does anyone know?

    BTW, I tried using compound quotes around the file path but the shell command didn't like that either and gave this error...

    Code:
    /bin/bash: -c: line 0: unexpected EOF while looking for matching ``'
    /bin/bash: -c: line 1: syntax error: unexpected end of file
    The final new instance of Stata doesn't get called because of this error.

    Thanks,
    Lance
Working...
X