Executing Shell script from Java code

馋奶兔 提交于 2019-12-13 04:12:55

问题


I have the gui which have the button as "mount to server"....am having the ubuntu client and server system.....When I click the mount button ,it should mount to server folder... for example, one folder name "OUTPUT" is in the server..in client machine folder is "OUTPUT FILES"...through linux command i can mount the server "OUTPUT" folder from client folder "OUTPUT FILES".... But , in java when i press the mount button, it should mount the server "OUTPUT" folder..should i need any shellscript code?...how to do? and how to get the server system ip address?...can u plz anyone help me?


回答1:


You can write a shell script to mount the server folder onto your client's filesystem. Once you have that working, you can just execute this shell script from Java code using Runtime class.

    String IPAddress = "...";
    String script= "/path/to/your/script.sh";
    String[] cmd = {script, IPAddress};
    Runtime rt = Runtime.getRuntime();
    rt.exec(cmd);


来源:https://stackoverflow.com/questions/5257094/executing-shell-script-from-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!