Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10639 > unrolled thread
| Started by | lbrt chx _ gemale |
|---|---|
| First post | 2011-12-10 06:01 +0000 |
| Last post | 2011-12-12 14:31 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
(java.lang.Runtime()).exec(new String[]) ... lbrt chx _ gemale - 2011-12-10 06:01 +0000
Re: (java.lang.Runtime()).exec(new String[]) ... Lew <lewbloch@gmail.com> - 2011-12-09 23:00 -0800
Re: (java.lang.Runtime()).exec(new String[]) ... Roedy Green <see_website@mindprod.com.invalid> - 2011-12-10 02:44 -0800
Re: (java.lang.Runtime()).exec(new String[]) ... Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-12-12 14:31 +0000
| From | lbrt chx _ gemale |
|---|---|
| Date | 2011-12-10 06:01 +0000 |
| Subject | (java.lang.Runtime()).exec(new String[]) ... |
| Message-ID | <1323496863.17965@nntp.aceinnovative.com> |
Something like this:
~
Process proc = (java.lang.Runtime()).exec((new String[]{"ls", "-l", "/media/sda1/Physical_Basis.flv"}));
~
works just fine.
~
Why doesn't something like, say:
~
Process proc = (java.lang.Runtime()).exec((new String[]{"date;", "time","ls", "-l", "/media/sda1/Physical_Basis.flv;", "date;"}));
~
work?
~
lbrtchx
comp.lang.java.programmer
[toc] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-12-09 23:00 -0800 |
| Message-ID | <29544146.1320.1323500401535.JavaMail.geo-discussion-forums@prkz16> |
| In reply to | #10639 |
(unknown) wrote:
> Something like this:
Not too very like, I think -
> Process proc = (java.lang.Runtime()).exec((new String[]{"ls", "-l", "/media/sda1/Physical_Basis.flv"}));
> ~
> works just fine.
except that it won't compile, as Stefan hinted.
> Why doesn't something like, say:
> ~
> Process proc = (java.lang.Runtime()).exec((new String[]{"date;", "time","ls", "-l", "/media/sda1/Physical_Basis.flv;", "date;"}));
> ~
> work?
For starters, for the same reason the other one doesn't.
Please reply with a copy-and-paste of the output from 'javac' on these idioms, placed into an SSCCE, of course.
A minor point unrelated to your major question - you never have to specify 'java.lang' for the types in that package. Just 'Runtime' will do nicely, thank you.
<http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html>
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-12-10 02:44 -0800 |
| Message-ID | <kvd6e7d7jt9dlo0iuom73gc39hcvetd02e@4ax.com> |
| In reply to | #10639 |
On 10 Dec 2011 06:01:03 GMT, lbrt chx _ gemale wrote, quoted or
indirectly quoted someone who said :
>~
> Why doesn't something like, say:
>~
> Process proc = (java.lang.Runtime()).exec((new String[]{"date;", "time","ls", "-l", "/media/sda1/Physical_Basis.flv;", "date;"}));
because date and time are not programs, but elements of a script that
requires a commend interpreter program.
See http://mindprod.com/jgloss/exec.html
for how to spawn a command interpreter.
--
Roedy Green Canadian Mind Products
http://mindprod.com
For me, the appeal of computer programming is that
even though I am quite a klutz,
I can still produce something, in a sense
perfect, because the computer gives me as many
chances as I please to get it right.
[toc] | [prev] | [next] | [standalone]
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Date | 2011-12-12 14:31 +0000 |
| Message-ID | <9kmhheFk40U1@mid.individual.net> |
| In reply to | #10639 |
On 10/12/11 06:01, lbrt chx _ gemale wrote:
> Something like this:
> ~
> Process proc = (java.lang.Runtime()).exec((new String[]{"ls", "-l", "/media/sda1/Physical_Basis.flv"}));
> ~
> works just fine.
> ~
> Why doesn't something like, say:
> ~
> Process proc = (java.lang.Runtime()).exec((new String[]{"date;", "time","ls", "-l", "/media/sda1/Physical_Basis.flv;", "date;"}));
> ~
> work?
> ~
Besides the other problems, even if the code were executable it would
fail because you are attempting to run a sequence of commands.
Process.exec() runs one command, the first argument. The rest of the
string elements are arguments to that command. It will not run a
sequence of commands as implied by the ";" ending each of the first two
commands. That requires you to use a shell to interpret the command
sequence.
--
Nigel Wade
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web