Call shell script in java?

Is it possible to call shellscript or shellcode in a java class ?

My code (in a static method):

Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec("/bin/bash");
BufferedWriter outCommand = new BufferedWriter(new
OutputStreamWriter(child.getOutputStream()));
outCommand.write("streamer -c /dev/video0 -b32 -o test.jpeg");
outCommand.flush();
outCommand.close();
child.destroy();

But I get this error if I try this code on my jsp page (tomcat6):

java.security.AccessControlException: access denied (running java.io.FilePermission / bin / bash)

Any solution to this problem?

EDIT : ls -l / bin / bash shows me the following line:

-rwxr-xr-x 1 root root 875596 2009-09-14 07:09 / bin / bash

thank

+3
source share
3 answers

, , , , Tomcat. /var/lib/tomcat6/conf/policy.d.

SO . AllPermissions , SecurityManager . , , , JavaScript, - , - , - .

+3

. /etc/init.d/tomcat6 :

TOMCAT_SECURITY=yes

:

TOMCAT_SECURITY=no

Tomcat:

/etc/init.d/tomcat6 restart

, , ( IMO).

+1

Also, if possible, try running it in a single exec call.

Process p = Runtime.getRuntime().exec(args);

where args is a string array of arguments.

String[] args = new String[] {"/bin/bash", "streamer", "-c", "/dev/video0", "-b32", "-o", "test.jpeg" };
+1
source

Source: https://habr.com/ru/post/1765450/


All Articles