LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cannot mount a Samba share using Java's Runtime().exec() (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-mount-a-samba-share-using-javas-runtime-exec-765286/)

awp2513 10-29-2009 07:53 AM

Cannot mount a Samba share using Java's Runtime().exec()
 
Hello,

I have a Java program that must be used to mount a Windows share using Samba. However, when I try to mount a shared folder like this:

String command = "mount -n -t smbfs -o guest //Host/Share/ /mnt/Host/Share";
Runtime.getRuntime().exec(command).waitFor();

I get the error "SMB connection Failed"

I have tried the exec command both with and without .waitFor() and "sudo mount..."

The command itself works when I enter it on the command line or if I run the command in a bash script.

So why don't I just do those methods? Well, there are several reasons. The most important is that this is being added to existing code and it must take this particular form.

I don't see why this shouldn't work, but then again, I'm new at this. No documentation I've come across has hinted at all as to why this won't work. This may be a "java question" and not a "Linux" one, but I was hoping somebody had fought with this before and knows the answer or where to find it.

Thanks in advance

dragonnefyre 10-29-2009 11:54 PM

Hi,

if it works on the command line or a shell then it looks more like a java problem. I don't know much about java. Are "host" and "share" variables set earlier or are they hard coded? If they are set elsewhere maybe you could hardcode the values and see if that works. Perhaps you could add a line that echoes the value of string command? I guess you may have done it already, just thought I should mention it.

awp2513 10-30-2009 07:43 AM

Yes, /Host/Share is a placeholder for a string in my code. I have verified that the command is correct (by entering it on the command line) and that when the method containing this code is called that the string has the value I expect.

From what I've read, there a few different flavors of exec (take different arguments). It may be that it is parsing my input incorrectly without me knowing it, and using the exec(string[],...) version may solve the issue. I'm not sure though.

Thanks!


All times are GMT -5. The time now is 01:42 PM.