[英]Execute cmd command in Java Applet
I'm trying to execute cmd command in Java applet, I tried this code 我正在尝试在Java applet中执行cmd命令,我尝试了这段代码
import java.io.InputStream;
import java.io.IOException;
import java.applet.Applet;
import java.awt.*;
public class execute extends Applet{
String output="";
public void init(){
try {
// Execute command
String command = "MYCMDCOMMAND";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c= in.read();
while ((c = in.read()) != -1) {
output =output+((char)c);
}
in.close();
}
catch (IOException e) {
}
System.out.println(output);
}
public void paint(Graphics g){
g.drawString(output,60,100);
}
}
And then wrote this html file and saved it in the same directory: 然后编写此html文件并将其保存在同一目录中:
<html>
<head><title>Applet</title>
<body>
<applet code="execute.class",height="200" width="200">
</body>
</html>
What I'm trying to do here is to run the ls shell command in an applet and display the results. 我在这里要做的是在applet中运行ls shell命令并显示结果。
The code compiles with no errors. 该代码编译没有错误。 But when I open the html file in the browser, I just get a gray square.
但是,当我在浏览器中打开html文件时,我只会看到一个灰色方块。
Is this because of security issues that I don't get anything? 是因为安全问题我什么也没得到吗? Or is it because of an error in the code?
还是因为代码错误?
You must be careful about some things. 您在某些事情上必须小心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.