简体   繁体   English

从java / Child Shell执行mount命令无法访问已安装的目录

[英]Executing mount command from java / Child Shell cannot access the mounted directories

I have a python script that needs to be executed from java code . 我有一个需要从java代码执行的python脚本。 I use the below command : 我使用以下命令:

 ScriptResult result = executor.executeCommand(Script,
            params.getParams(), false);

But executor.executeCommand() forks a new shell . 但是executor.executeCommand()分叉了一个新的shell。 I had run a mount command earlier and the contents of /mnt/folder1 are accessible from parent shell but not accessible from the newly forked child shell . 我之前已经运行过mount命令,并且/ mnt / folder1的内容可以从父shell访问,但是不能从新创建的子shell访问。

I have tried to execute the mount command , just before the executor.executeCommand() step using the following : 我尝试使用以下命令在executor.executeCommand()步骤之前执行mount命令:

     String cmd = new String("/bin/mount ip:/folder1 /mnt/folder1");
     Process p = new ProcessBuilder(cmd).start();

and also 并且

    String cmd = new String("mount"); String[] arg = new
    String[]{" ip:/folder1 ,"/mnt/folder1"}; Process pr =
 Runtime.getRuntime().exec(cmd); 

Both these give the following error : 这两个都产生以下错误:

    java.io.IOException: Cannot run program "mount ip:/folder1 /mnt/folder1":
    error=2, No such file or directory                      
   at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)                      
   at Caused by: java.io.IOException: error=2, No such file or directory

I have made a myscript.sh and copied the mount command and the python script command into the myscript . 我制作了一个myscript.sh ,并将mount命令和python脚本命令复制到myscript中。 I invoked the myscript throgh java code and it was successful . 我通过Java代码调用了myscript,它成功了。 But I should invoke the mount command from java code and not through a seperate script . 但是我应该从Java代码而不是通过单独的脚本调用mount命令。 Is there any way that I missed out. 有什么我错过的方法吗? Thanks in advance . 提前致谢 。

try changing 尝试改变

 String cmd = new String("/bin/mount ip:/folder1 /mnt/folder1");

 Process p = new ProcessBuilder(cmd).start();

to

String[] cmd = new String[]{"/bin/mount", "ip:/folder1", "/mnt/folder1"};

Process p = new ProcessBuilder(cmd).start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM