티스토리 뷰

반응형

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

 

public class Test {

public static void main(String[] args) throws Exception {

String command = "ls -al";

shellCmd(command);

}

public static void shellCmd(String command) throws Exception {

Runtime runtime = Runtime.getRuntime();

Process process = runtime.exec(command);

InputStream is = process.getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String line;

while ((line = br.readLine()) != null) {

System.out.println(line);

}

}

}

// java에서 리눅스 명령어 실행

 

반응형

'Study' 카테고리의 다른 글

MySQL(마이에스큐엘) 관련  (1) 2024.03.15
DB(디비) Tool(도구) 관련  (0) 2024.03.15
Hash(해시) 관련  (0) 2024.02.18
Apache(아파치) Install(설치)  (0) 2024.02.18
cygwin(시그윈) 관련  (0) 2024.02.18
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함