exec command under Unix

From: Matthew Ogan (mattogan_at_hotmail.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 04:58:23 GMT

I can execute commands using "Runtime.getRuntime().exec( command );" on a
Sun workstation but I cannot get a command with redirects or pipes to work
(passing the command and arguments as a string or an array of strings). I
realize that the redirect/pipe is not a command argument but I hope there is
some way to send the non-argument characters to the command prompt of the
operating system.

Maybe some examples will clarify my dilemma:

Runtime.getRuntime().exec( "ls -l"); works
Runtime.getRuntime().exec( "ls -l > junk"); does not work

String command[] = {"ls", "-l"};
Runtime.getRuntime().exec(command); works

String command[] = {"ls", "-l", ">", "junk"};
Runtime.getRuntime().exec(command); does not work



Relevant Pages

  • Re: System() question
    ... Why does a call to systemwork by passing the command line string ... This is causing problems when running in a chroot ...
    (comp.lang.c)
  • Re: exec command under Unix
    ... > Sun workstation but I cannot get a command with redirects or pipes to work ... > (passing the command and arguments as a string or an array of strings). ... Invoking the shell using the '-c' option forces the use of the entire string ... which immediately follows as shell input, ...
    (comp.lang.java.help)
  • Re: How to use xargs with a shell redirect
    ... command with redirects in it? ... Every time I do a CVS update, I get merge conflicts on these files. ... like a perfect opportunity for the shell (BASH shell, ...
    (comp.unix.shell)
  • How to use xargs with a shell redirect
    ... command with redirects in it? ... like a perfect opportunity for the shell (BASH shell, ... to do this with xargs... ...
    (comp.unix.shell)
  • Re: how to close form after running code?
    ... You can fire a proceedure referenced by name in a string by using the Run ... command and passing it the name of the proceedure to fire. ...
    (microsoft.public.access.formscoding)