Skip to content

anonymous /Myshell.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
I have also tried:
=================
$ touch /tmp/bash.sh
$ chmod +x /tmp/bash.sh
$ echo "sudo convert /tmp/testing.tiff /tmp/testing.jpg" > /tmp/bash.sh
$ java -jar Myshell.jar # note: system("/tmp/bash.sh"); was used as absolute path
[sudo] password for alex:
package installer;
import java.io.*;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.Properties;
/* Use: call it from other class as: Myshell.system("sudo convert /tmp/testing.tiff /tmp/testing.jpg");
*/
public class Myshell
{
public static String system(String cmd)
{
String value = "";
try
{
Process p=Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
value += line + "\n\r";
line=reader.readLine();
}
} catch(IOException e1) {
} catch(InterruptedException e2) {
}
return value;
}
}
$ whoami
alex
$ which java
/usr/bin/java
$ which convert
/usr/bin/convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.