running linux command in jsp

774 views
Skip to first unread message

etika ahuja

unread,
Feb 21, 2011, 1:47:00 AM2/21/11
to iit...@googlegroups.com
i want to run linux command through a jsp

i tried as follows but its not working pls help

<%@ page import="java.io.*"%>
<%

try
{
Process p=null;
 Runtime r=Runtime.getRuntime();
String cmd="sh /bin/date>/home/etika/Desktop/aaa/mm.txt";
p=r.exec(cmd);
p.waitFor();

}

catch(Exception e)
{
out.println(e);
}
%>

Narendra Sisodiya

unread,
Feb 21, 2011, 6:07:57 AM2/21/11
to iit...@googlegroups.com, etika ahuja
On Mon, Feb 21, 2011 at 12:17 PM, etika ahuja <etika...@gmail.com> wrote:
i want to run linux command through a jsp

i tried as follows but its not working pls help

<%@ page import="java.io.*"%>
<%

try
{
Process p=null;
 Runtime r=Runtime.getRuntime();
String cmd="sh /bin/date>/home/etika/Desktop/aaa/mm.txt";

 
try
String cmd="bash /bin/date>/home/etika/Desktop/aaa/mm.txt";
String cmd="/bin/date>/home/etika/Desktop/aaa/mm.txt";
String cmd="date>/home/etika/Desktop/aaa/mm.txt";

etika ahuja

unread,
Apr 19, 2011, 3:19:31 PM4/19/11
to nare...@narendrasisodiya.com, iit...@googlegroups.com






hello

information:
tomcat6 is running my jsp page ,so all the linux commands too are executed by tomcat6.
but i want to run these linux commands from a different user etika on my system through this jsp page which is executed by tomcat.

(on running the linux commannd the ownership of the file gets changes to tomcat6 but i don't want the ownership of the file to be changed on executing it ,so can i run this linux command from a different user etika so that my ownership doesnot changes )

 

ankur kumar

unread,
Apr 20, 2011, 4:55:13 AM4/20/11
to iit...@googlegroups.com
In case you only want the date from the server, you can try the
java.util.Date Class from the Java library as well.

> --
> LUG@IITD - http://lug-iitd.org/Footer
>


--
Ankur Kumar
Pre-Final Year
Masters in Computer Applications
Birla Institute of Technology
MESRA
Ranchi - 835215

Mobile: +91-9162971729

Reply all
Reply to author
Forward
0 new messages