Re: running linux cmd in servlet/jsp

Toru Watanabe <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <86y92tgmqx.wl%[email protected]>
Hi, OOI,

When you input
/sbin/ifconfig eth1 | grep HWaddr | awk '{print $5; }'
in console, then it will work fine. Because shell(interpreter) can parse
your command and fork three processes, ifconfig eth1, grep HWaddr, and
awk '{print $5; }' these are connected by pipe.

But your code
KL>   proc1 = rt1.exec("/sbin/ifconfig eth1 | grep HWaddr | awk '{print $5; }' ");
must not work because pipe "|" and followed commands will be passed to ifconfig as arguments.

So you should write
proc 1 = rt1.exec("/bin/sh -c \"/sbin/ifconfig eth1 |grep HWaddr | awk '{print \\$5; }'\"");
or use shell script like following.
---snip
#!/bin/sh
/sbin/ifconfig eth1 |grep HWaddr |awk '{print $5; }'
---snip

I highly recommend shell script because it is easy to change commands.

Regards,
Watanabe

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.