Skip to main content
1-Visitor
June 17, 2011
Question

Running system/sh commands

  • June 17, 2011
  • 5 replies
  • 1168 views
This is related to my Java questions yesterday. I actually got into the
Java work because I was having troubles verifying that the ACL system or
sh commands were working.

Today I was able to get this to work:

sh 'C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat'

I need to pass it a parameter though, and I get a message that the
parameter isn't understood if I do this:

sh 'C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat' deploy

And in this version the cmd window just flashes by doing nothing:

sh 'C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat deploy'

I suppose I could just create another batch file that contains the
parameter, but I would like to use the tools as provided if I can.

I've also tried the system function, which seems to do nothing:

system("C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat")




    5 replies

    18-Opal
    June 17, 2011
    Hi Dan--

    In this case you probably need separate quotes around your exe path that get passed through to the shell since the path contains spaces. Try something like this:

    sh "C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat" deploy'

    --Clay


    1-Visitor
    June 17, 2011
    nope that combinations flashes by as well

    > Hi Dan--
    >
    > In this case you probably need separate quotes around your exe path that
    > get passed through to the shell since the path contains spaces. Try
    > something like this:
    >
    > sh "C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat" deploy'
    >
    > --Clay
    >
    >
    >
    1-Visitor
    June 24, 2011
    Caveats: I found some examples in code I wrote a long time ago. I do not
    remember the why's and wherefore's of how I put the commands together, only
    that it took some experimentation. Further, these are commands assigned to
    menus, and so may behave differently than something you're running more
    interactively. With all that in mind ...

    Try assigning the commands and operands to variables before executing them.
    For example:

    batch='C:\Program Files\nsiv3.1.15.2\bin\makedoc.bat'
    operand='deploy'
    sh $batch $operand

    Try also ending the command with a & which has runs the command
    asynchronously (doesn't wait for it to complete/return).

    sh $batch $operand &

    June 24, 2011
    I do run a fair amount of system/sh commands, and I've found I have the
    best luck when I save commands and args/params in variables.



    One thing that complicates the crap out of using system/sh is if you
    have a param/arg (like a system path) that might include a space. Then
    you have to do the whole "trying to encapsulate single quotes in double
    quotes so the quotes actually get passed over to the shell" thing.



    Don't even get me started on the pattern matching an escape character
    for the stupid gsub().



    Yeah, just out of curiosity, has anyone ever noticed that sometimes it
    seems like certain regexp patterns that work when using "find" don't
    always play well with funcs that take a regexp as an arg? I already
    know I'm crazy, but I'd swear this one isn't just me...



    -Jason


    1-Visitor
    June 25, 2011
    thanks all for the ideas. My situation was simple
    enough that I ended up just writing another .bat
    file and executing it. Not pretty but it got me a proof of concept.

    ..dan