[英]How to access linux command such as sed,awk from java
自上個月以來,我一直在研究JNI(Java本機接口)。這真的很有趣。我的意思是從C調用Java函數,反之亦然。現在我有一個意圖調用linux命令,我在上面提到過,就像從Java端的sed,awk一樣。我也對Linux的銷售腳本有一點了解。 請給我一些提示如何執行此操作。
您應該運行Runtime.exec()或ProcessBuilder,具體取決於將進程執行到本地系統所需的條件。
這個問題可以幫助:
您可以使用以下Java代碼段運行shell命令:
Process process = Runtime.getRuntime().exec("echo This is a test"); //Start the process
process.waitFor(); //Wait for the process to terminate
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); //Get the output
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.