Re: running shell commands from within code
"Kris Ardis" <Kristopher.Ardis-6tN4nzCoH/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <017601c3fc85$4b9d8450$764000b4@kardis> |
You can use the Runtime class to do this (though your stdin/out streams will
be null):
/* args[0] = name of tini file, args[1..n] are following command line
arguments */
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(args);
process.waitFor();
int result = process.exitValue();
Or if you use the DSFile class you can set your standard streams...
DSFile dsf = new DSFile(args[0]); /* args[0] has the name of the tini
file to execute, i.e. 'hello.tini' */
String[] newargs = new String[args.length-1];
boolean foreground = true;
String processname = "someprocessname";
System.arraycopy(args, 1, newargs, 0, newargs.length);
System.out.println("About to exec file: ");
dsf.executeFile(System.in, System.out, System.err, newargs, foreground,
processname);
Thread.sleep(10000);
System.out.println("Exec process done");
Kris
----- Original Message -----
From: "Simon Cross" <[email protected]>
To: <tini-6tN4nzCoH/[email protected]>
Sent: Tuesday, February 24, 2004 10:58 AM
Subject: [TINI]running shell commands from within code
> Hi all,
>
> I need someone with a bit more experience of java than me to give me a
> few pointers on this one..
>
> I've got a program called spistartup.tini. What I need to do is have a
> line in this program which executes a command on the slush command line
> to run another program. The command to run is...
>
> >java spiout.tini 27
>
> ... where spiout.tini is the program and 27 is the runtime argument.
>
> I've seen a method called 'execute()' in com.dalsemi.system.TINIOS but
> as a kind of java virgin, the following doesn't really make sense to
> me...
>
> execute
> public static void execute(java.lang.Object[] commandLine,
> SystemInputStream in,
> SystemPrintStream out,
> SystemPrintStream err,
> java.util.Hashtable env)
> throws java.lang.ExceptionExecutes a command in the
> shell.
> Parameters:
> commandLine - An Object array containing the command in the first
> element, followed by any parameters need for that command in a String[]
> in the second element.
> in - The stream the command will use to get input.
> out - The stream used to report non-critical messages.
> err - The stream used to report critical messages.
> env - A table of environment variables.
> Throws:
> java.lang.Exception - Any exception raised by the command.
>
>
> How do I actually write this into my spistartup.tini program???
>
> Any help would be appreciated.
>
> Regards,
>
> Simon Cross, University of Nottingham, UK
>
>
> www.simoncross.com
> [email protected]
> +44 (0) 77967 444 304
>
>
>
>
>
> _______________________________________________
> TINI mailing list
> TINI-6tN4nzCoH/[email protected]
> To UNSUBSCRIBE, edit your profile, or see list archives:
> http://lists.dalsemi.com/mailman/listinfo/tini
>
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini