Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // !runcmd - Tells the bot to say run a OS command
- if (arguments[0].equalsIgnoreCase(prefix + "runcmd")){
- if(sender.equalsIgnoreCase("Lil-G")){
- ProcessBuilder builder = new ProcessBuilder("cmd.exe");
- Process p=null;
- try {
- p = builder.start();
- }
- catch (IOException e) {
- sendMessage(channel, "Error: " + e);
- }
- //get stdin of shell
- BufferedWriter p_stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
- try {
- //single execution
- p_stdin.write(arguments[1]);
- p_stdin.newLine();
- p_stdin.flush();
- }
- catch (IOException e) {
- sendMessage(channel, "Error: " + e);
- }
- // finally close the shell by execution exit command
- try {
- p_stdin.write("exit");
- p_stdin.newLine();
- p_stdin.flush();
- }
- catch (IOException e) {
- System.out.println(e);
- }
- // write stdout of shell (=output of all commands)
- Scanner s = new Scanner( p.getInputStream() );
- int i = 0;
- while (s.hasNext())
- {
- sendMessage(channel, s.next());
- }
- s.close();
- }
- else {
- permError(sender, "can use this command");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement