Javaµ÷ÓÃLinuxÃüÁîÐÐÈô¸ÉʵÀý
Executing a CommandSee also e90 Reading Output from a Command.
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp";
child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array:
try {
// Execute a command with an argument that contains a space
String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
Process child = Runtime.getRuntime().exec(commands);
} catch (IOException e) {
}
e90. Reading Output from a Commandtry {
// Execute command
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
e91. Sending Input to a Commandtry {
// Execute command
String command = "cat";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("some text".getBytes());
out.close();
} catch (IOException e) {
}
Ïà¹ØÎĵµ£º
ÏîÄ¿Öг£Óöµ½ÐèÒª¶ÔĿǰÔËÐеÄϵͳ½øÐÐЧÂÊ·ÖÎö£¬»òÅöµ½¿Í»§×ÉѯÈçºÎÓÅ»¯ÏµÍ³µÄЧÂÊÎÊÌâ¡£¸ü¶àµÄÇé¿öÊÇ£¬ÔÚϵͳ³öÏÖÎÊÌâµÄʱºò£¬ÐèÒª·ÖÎöÔÒò£¬¶¨Î»ÏµÍ³¹ÊÕÏ»òÆ¿¾±£¬µ±È»£¬×îºÃÊÇ¿ÉÒÔÒ»²¢½â¾ö¹ÊÕÏ¡£µ«Êµ¼ÊÉÏ£¬²Ù×÷ϵͳÓÅ»¯ÊÇÒ»¸ö·Ç³£¸´ÔÓµÄÎÊÌ⣬¿öÇÒlinuxÓÐ×Ô¼ºÒ»Ì×ÓбðÓÚÆäËû²Ù×÷ϵͳ¹ÜÀíµÄ»úÖÆ£¬ÓÉ´Ë»áÒýÆðºÜ¶à²»±ØÒªµÄÎ ......
IPµØÖ·ÊÇÒ»¸ö32λµÄ¶þ½øÖÆÊý£¬ËüÓɵã·ÖÊ®½øÖƼǷ¨±íʾ£¬Ã¿Ò»¸öÊ®½øÖÆÊý´ú±íÒ»¸ö8λÎÞ·ûºÅÕûÐÍÊý£¬ËùÒÔ·¶Î§ÔÚ0-255Ö®¼ä¡£
Ò»¸öIPµØÖ··ÖÎªÍøÂçµØÖ·ºÍÖ÷»úµØÖ·£¬ÍøÂçµØÖ·Çø·Ö²»Í¬ÍøÂ磬Ö÷»úµØÖ·Çø·ÖÏàÍ¬ÍøÂçÖв»Í¬Ö÷»ú¡£²»Í¬µÄIPµØÖ·ÀàËûÃǵÄÖ÷»úÍøÂçµØÖ·Ò²ÊDz»¹Ì¶¨µÄ£¬A,B,CÀàµØÖ·¶¨ÒåÁËijһÖ÷»úÌØ¶¨µÄIPµØÖ·£ ......
Òª½«Îļþϵͳ¹ÒÔØµ½ÎÒÃÇµÄ Linux ϵͳÉÏ£¬
¾ÍҪʹÓà mount Õâ¸öÖ¸Áî
Ó÷¨:
mount [-tonL] ×°ÖÃÃû³Æ´úºÅ ¹ÒÔØµã
mount -a
²ÎÊý£º
-a £ºÒÀÕÕ /etc/fstab µÄÄÚÈݽ«ËùÓÐÏà¹ØµÄ´ÅÅ̶¼¹ÒÉÏÀ´£¡
-n £ºÒ»°ãÀ´Ëµ£¬µ±ÎÒÃǹÒÔØÎļþϵͳµ½ Linux ÉÏͷʱ£¬ Linux »áÖ÷¶¯µÄ½«
&nbs ......
2.ÉèÖû·¾³±äÁ¿¡£
#vi /etc/profile
ÔÚ×îºóÃæ¼ÓÈë
#set java environment
export JAVA_HOME=/usr/java/jdk-1_5_0_02
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
:$JAVA_HOME/lib/mysql-connector-java-3.2.0.jar:$JAVA_HOME/lib/classes12.jar
export PATH=$PATH:$JAVA_ ......
ps -ef|grep tomcat ²é¿´ÕýÔÚÆô¶¯µÄÏß³Ì
cd .. ÍË»ØÉÏÒ»¼«
ls Áгöµ±Ç°Ä¿Â¼µÄÎļþ
kill -9 [Ï̺߳Å] ¹Ø±ÕÏß³Ì
su - root µÇ½Õ˺Å
ÔĶÁ(0)| ÆÀÂÛ(14)| ·ÖÏí(0) ½ÏÐÂһƪ:ת£º´øËÑË÷·ÖÒ³µÄgird ½Ï¾Éһƪ:·è×Ó ÆÀÂÛ| ÔÞ
ÖÜ˧ 2010-01-26 18:23
su - root µÇ½Õ˺Å
ÖÜ˧ 2010-01-26 19:53
......