1. Script test.sh, placed in the/users/hdwang directory
#!/bin/sh/users/hdwangechols: 'ls'for (( i=1; i<=; i++)); Do Echo $ (expr31); Sleep 1s Done echo JPS: ' Jps-l '
2.java Execution test.sh
Public classExecshell { Public Static voidMain (string[] args) {Try{Process Pro= Runtime.getruntime (). EXEC ("/users/hdwang/test.sh"); InputStream in=Pro.getinputstream (); BufferedReader Read=NewBufferedReader (NewInputStreamReader (in)); String Line=NULL; while(line = Read.readline ())! =NULL) {System.out.println (line); } pro.waitfor (); } Catch(Exception e) {e.printstacktrace (); } }}
3. Implementation results
Ls:app applications Desktop Documents Downloads Library Movies Music Pictures Projects public a.html C Curl.txt java_error _in_idea.hprof mavenrepo nginx Configuration res sessiontmp test.sh record the machine configuration environment, such as the machine configuration environment. zip
4
7
10
13
16
19
22
25
28
31
jps:11617 sun.tools.jps.Jps 11592 org.jetbrains.jps.cmdline.Launcher 10633 org.jetbrains.jps.cmdline.Launcher 11593 Com.hdwang.ExecShell 10539 Com.hzxc.chess.server.Booter 555
Java executes shell scripts and outputs execution