You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Roman Mikhailov <ro...@tugboatmedia.com> on 2002/07/24 20:34:37 UTC

Unix command from jsp does not work

Hello everybody

I'm trying to execute a unix command from within the jsp page, smth like

Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","ls -l >
dat.foo"});

.. And it doesn't work, I mean nothing happens , no error messages, nothing


However this piece of code works fine in a standalone Java program
What am I doing wrong?

My system: Linux Red Hat 7.2, Apache 1.3.22, Tomcat 4.0.3, WARP Connector

Thanks in advance

roman



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Unix command from jsp does not work

Posted by Roman Mikhailov <ro...@tugboatmedia.com>.
On 7/24/02 1:12 PM, "Will Hartung" <wi...@msoft.com> wrote:

> From: "Roman Mikhailov" <ro...@tugboatmedia.com>
> Sent: Wednesday, July 24, 2002 11:34 AM
> Subject: Unix command from jsp does not work
> 
> 
>> I'm trying to execute a unix command from within the jsp page, smth like
>> 
>> Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","ls -l >
>> dat.foo"});
>> 
>> .. And it doesn't work, I mean nothing happens , no error messages,
> nothing
> 
> Well, if the ls -l happens to not find the file foo.dat, then it's proper
> result would be to, essentially, "do nothing". So, perhaps it actually is
> working, and the file you're running 'ls' on isn't there?
> 
> P.S. just an FYI, but you do realize that the java.io.File object does
> pretty much what 'ls' will do for you, right? Plus, it's portable...
> 
> Regards,
> 
> Will Hartung
> (willh@msoft.com)
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

ls -l > foo.dat was just an example
My task is to envoke a perl script from jsp which looks like this:
 Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","echo
blah@foo.com | /root/bin/bulkmakemail"});
For some reason I'm not able to run ANY unix commands from jsp
Can it be because of "user privileges" , do I have to run tomcat as root?
I know it is dangerous
Or is there any other way  I can fix this problem?

Thank you

roman



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Unix command from jsp does not work

Posted by Will Hartung <wi...@msoft.com>.
From: "Roman Mikhailov" <ro...@tugboatmedia.com>
Sent: Wednesday, July 24, 2002 11:34 AM
Subject: Unix command from jsp does not work


> I'm trying to execute a unix command from within the jsp page, smth like
>
> Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","ls -l >
> dat.foo"});
>
> .. And it doesn't work, I mean nothing happens , no error messages,
nothing

Well, if the ls -l happens to not find the file foo.dat, then it's proper
result would be to, essentially, "do nothing". So, perhaps it actually is
working, and the file you're running 'ls' on isn't there?

P.S. just an FYI, but you do realize that the java.io.File object does
pretty much what 'ls' will do for you, right? Plus, it's portable...

Regards,

Will Hartung
(willh@msoft.com)




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>