Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(java.lang.Runtime()).exec(new String[]) ...

22 views
Skip to first unread message

lbrtchx_gemale

unread,
Dec 10, 2011, 1:01:03 AM12/10/11
to
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
Message has been deleted

Lew

unread,
Dec 10, 2011, 2:00:01 AM12/10/11
to
(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

Roedy Green

unread,
Dec 10, 2011, 5:44:56 AM12/10/11
to
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.

Nigel Wade

unread,
Dec 12, 2011, 9:31:10 AM12/12/11
to
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

lbrtchx_gemale

unread,
Feb 6, 2012, 5:29:31 AM2/6/12
to
/*
Say you want to keep the local copies of documents you download/view online in a directory structure that somewhat resembles the URL path.
When you use firefox as the browser it seems to darken the FQDN, but then you can check it doesn't do it truthfully. Try for example:
~
http://www-hiel.ist.osaka-u.ac.jp/~iizuka/Hiroyuki_Iizuka.html
http://www.c.u-tokyo.ac.jp/eng_site/
~
Why is it that u-tokyo.ac.jp throws an UnknownHostException?
~
lbrtchx
~
*/

import java.net.*;
import java.util.*;

// __
public class GetCanonicalHostName{
public static void main(String[] args){
String[] aHNms = new String[]{"sussex.ac.uk", "ac.uk", "www.mathstat.dal.ca", "mathstat.dal.ca", "dal.ca", "www-hiel.ist.osaka-u.ac.jp", "ist.osaka-u.ac.jp", "osaka-u.ac.jp", "ac.jp" , "www.c.u-tokyo.ac.jp", "c.u-tokyo.ac.jp", "u-tokyo.ac.jp", "hardware.slashdot.org", "slashdot.org"};
// __
InetAddress ia = null;
for(int i = 0; (i < aHNms.length); ++i){
System.out.println("~");
System.out.println("// __ " + aHNms[i] + ":");
System.out.println("~");
try{
ia = InetAddress.getByName(aHNms[i]);
System.out.println(ia.getCanonicalHostName() + ": " + ia.getHostAddress());
}catch(UnknownHostException UnkHX){ UnkHX.printStackTrace(); }
}
System.out.println("~");
}
}

/*
$ java GetCanonicalHostName
~
// __ sussex.ac.uk:
~
139.184.32.141: 139.184.32.141
~
// __ ac.uk:
~
java.net.UnknownHostException: ac.uk
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at java.net.InetAddress.getByName(InetAddress.java:1014)
at GetCanonicalHostName.main(GetCanonicalHostName.java:22)
~
// __ www.mathstat.dal.ca:
~
support.MathStat.Dal.Ca: 129.173.118.86
~
// __ mathstat.dal.ca:
~
support.MathStat.Dal.Ca: 129.173.118.86
~
// __ dal.ca:
~
Dal.Ca: 129.173.1.241
~
// __ www-hiel.ist.osaka-u.ac.jp:
~
marino.ise.eng.osaka-u.ac.jp: 133.1.52.68
~
// __ ist.osaka-u.ac.jp:
~
java.net.UnknownHostException: ist.osaka-u.ac.jp
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at java.net.InetAddress.getByName(InetAddress.java:1014)
at GetCanonicalHostName.main(GetCanonicalHostName.java:22)
~
// __ osaka-u.ac.jp:
~
java.net.UnknownHostException: osaka-u.ac.jp
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at java.net.InetAddress.getByName(InetAddress.java:1014)
at GetCanonicalHostName.main(GetCanonicalHostName.java:22)
~
// __ ac.jp:
~
java.net.UnknownHostException: ac.jp
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at java.net.InetAddress.getByName(InetAddress.java:1014)
at GetCanonicalHostName.main(GetCanonicalHostName.java:22)
~
// __ www.c.u-tokyo.ac.jp:
~
park.itc.u-tokyo.ac.jp: 133.11.205.76
~
// __ c.u-tokyo.ac.jp:
~
park.itc.u-tokyo.ac.jp: 133.11.205.76
~
// __ u-tokyo.ac.jp:
~
java.net.UnknownHostException: u-tokyo.ac.jp
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at java.net.InetAddress.getByName(InetAddress.java:1014)
at GetCanonicalHostName.main(GetCanonicalHostName.java:22)
~
// __ hardware.slashdot.org:
~
star.slashdot.org: 216.34.181.48
~
// __ slashdot.org:
~
slashdot.org: 216.34.181.45
~
*/

lbrtchx_gemale

unread,
Feb 6, 2012, 5:31:11 AM2/6/12
to

lbrtchx_gemale

unread,
Feb 6, 2012, 5:33:07 AM2/6/12
to

Steven Simpson

unread,
Feb 6, 2012, 6:53:50 AM2/6/12
to
On 06/02/12 10:33, lbrt chx _ gemale wrote:
> /*
> Say you want to keep the local copies of documents you download/view online in a directory structure that somewhat resembles the URL path.
> When you use firefox as the browser it seems to darken the FQDN,

Took me a while to work out what you meant. As I see it, it leaves a
portion of the authority black, and lightens the other parts.

> but then you can check it doesn't do it truthfully. Try for example:
> ~
> http://www-hiel.ist.osaka-u.ac.jp/~iizuka/Hiroyuki_Iizuka.html
> http://www.c.u-tokyo.ac.jp/eng_site/
> ~
> Why is it that u-tokyo.ac.jp throws an UnknownHostException?

What makes you think that FF is claiming that the highlighted portion of
the authority is strictly a 'host' name?

> java.net.UnknownHostException: u-tokyo.ac.jp
> at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
> at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
> at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
> at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
> at java.net.InetAddress.getAllByName(InetAddress.java:1128)
> at java.net.InetAddress.getAllByName(InetAddress.java:1064)
> at java.net.InetAddress.getByName(InetAddress.java:1014)
> at GetCanonicalHostName.main(GetCanonicalHostName.java:22)

$ host u-tokyo.ac.jp
u-tokyo.ac.jp mail is handled by 20 utmail2.nc.u-tokyo.ac.jp.
u-tokyo.ac.jp mail is handled by 10 utmail3.nc.u-tokyo.ac.jp.


--
ss at comp dot lancs dot ac dot uk

0 new messages