Linux Java Remote call
10月21日
echo "###########################################" date echo "hi this is called from the Web, so you could call from any where in the world!" date echo $PATH echo "end of demo" echo "thank you !" mozilla-firefox sleep 2
===========================
package com.kbhy.micas;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Commander {
public static void main(String[] args) {
System.out.println(runCommand());
}
public static String runCommand() {
StringBuffer sbf = new StringBuffer();
try {
System.out.println("##########################");
String [] a = {"/bin/sh","-c","/home/micas/mywork/src/tt.cmd"};
Process p = Runtime.getRuntime().exec(
a);
InputStream i = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(i));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
sbf.append(line + "\r\n<br>");
}
} catch (Exception ex) {
sbf.append(ex.toString());
}
System.out.println(sbf);
System.out.println("###########################");
return sbf.toString();
}
}
=======================
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<%
try {
out.println(com.kbhy.micas.Commander.runCommand());
} catch (Exception ex) {
out.println(ex);
}
%>
</body>
</html>