java.lang.Runtime.getRuntime().exec(String s);
解决方案 »
- 如何利用SpringSecurity验证Email和Password?
- spring里用getCurrentSession获取的session不在事务管理,请教
- 如何让部署在liferay portal上的jspportlet支持WAP访问?
- Tomcat中如何在应用程序中访问JNDI?
- 一个无聊的问题
- ResultSet set = stmt.executeQuery(SQL);执行完后,数据是取到了本机还是在数据库服务器?
- 小声地问
- 我要学jsp,已经下载了j2ee1.4,需要一个支持jsp引擎的WEB服务器或jsp引擎!!(急,马上给分)
- 在哪儿可以下载EJB的编程规范?
- 求各位大神指点迷津
- 大家帮我看看tomcat报的异常是什么意思?急!
- Struts编译 的时候警告,运行的时候500错误,马上给分
import java.io.IOException;public class ExecLs { static public void main(String[] args) {
String cmd = "ls" try {
Process ps = Runtime.getRuntime().exec(cmds);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
} catch(IOException ioe) {
ioe.printStackTrace();
}
} // read an input-stream into a String
static String loadStream(InputStream in) throws IOException {
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while( (ptr = in.read()) != -1 ) {
buffer.append((char)ptr);
}
return buffer.toString(); }}
import java.lang.String;
import java.lang.*;
import java.io.*;
public class C
{
Process t=null;
public void run(){
try {
t=java.lang.Runtime.getRuntime().exec("cmd.exe /c start telnet 192.168.0.122");
telnet之后是输入口令 我在程序里怎么写才能直接登陆上啊?
[work@tracqhost jtom]$ javac C.java
[work@tracqhost jtom]$ java C
init-+-atd
|-bdflush
|-bonobo-activati
|-cannaserver
|-crond
|-eth0
|-eth1
|-gconfd-2
|-gnect
|-gnome-panel
|-gnome-settings-
|-gpm
|-httpd---20*[httpd]
|-in.proftpd---in.proftpd
|-irqbalance
|-java---java---41*[java] ////// 我想把41取出来做判断操作,请问该怎么做啊??
|-2*[jre] 或者取出整行也可以!
|-keventd
|-khubd
|-5*[kjournald]
|-klogd
|-kscand/DMA
|-kscand/HighMem
|-kscand/Normal
|-ksoftirqd_CPU0
|-ksoftirqd_CPU1
|-kswapd
|-kupdated
|-login---bash---startx---xinit-+-X
| `-gnome-session---ssh-agent
|-2*[login---bash]
|-mdrecoveryd
|-metacity
|-3*[mingetty]
|-nautilus---nautilus---5*[nautilus]
|-notification-ar
|-oafd
|-11*[oracle]
|-portmap
|-rpc.statd
|-safe_mysqld---mysqld---mysqld---9*[mysqld]
|-2*[sendmail]
|-sshd---sshd---sshd---bash
|-syslogd
|-tnslsnr
|-xfs
|-xinetd-+-fam
| |-in.telnetd---login---bash
| `-in.telnetd---login---bash---java---java-+-7*[java]
| `-java---pstree
`-xscreensaver---barcode我想把41取出来做判断操作,请问该怎么做啊??或者取出整行也可以!
public class a
{
public static void main(String[] args) throws Exception
{
Runtime rt = Runtime.getRuntime();
for(int i=0 ;i<100;i++)
{
String cmd = "linux command";
rt.exec(cmd);
}
}
}
public class a
{
public static void main(String[] args) throws Exception
{
Runtime rt = Runtime.getRuntime();
String cmd = "net send 192.168.0.45 hi";
rt.exec(cmd);
}
}
Runtime.getRuntime.exex(cmds);出错如下
C.java:16: illegal character: \92
String cmds="pstree | grep java |awk -F "---" ' {printf $3"\n"}' |awk -F
"*" ' {printf $1"\n"}'";
^
C.java:16: illegal character: \92
String cmds="pstree | grep java |awk -F "---" ' {printf $3"\n"}' |awk -F
"*" ' {printf $1"\n"}'"; ^
C.java:16: unexpected type
required: variable
found : value
String cmds="pstree | grep java |awk -F "---" ' {printf $3"\n"}' |awk -F
"*" ' {printf $1"\n"}'";
^
C.java:16: operator - cannot be applied to byte,java.lang.String
String cmds="pstree | grep java |awk -F "---" ' {printf $3"\n"}' |awk -F
"*" ' {printf $1"\n"}'";
^
4 errors
应该是Stringl类型里有非法字符 ,该怎么才能解决呢! 能在exec()里运行那个命令吗?该怎么写??