cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Running system/sh commands

ptc-953343
1-Newbie

Running system/sh commands

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 5

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


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
>
>
>

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 &

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


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

Top Tags