B4J Question Jshell question


Active Member
In terminal mode on my linux desktop I can mount a server/workstation directory with the following line:

sudo -S mount -t cifs -w -o username=service -o password=service // /home/microcut/shared

This successful mounts the shared directory locally on my linux desktop.

When I use the Jshell command in the following code block:

shl.Initialize("net","sudo -S mount -t cifs -w -o username=service -o password=service // /home/microcut/shared",Null)
shl.WorkingDirectory = "/home/microcut"

Sub net_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Error: " & StdErr)
    End If
End Sub

I get the following error:

Error: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "sudo -S mount -t cifs -w -o username=service -o password=service // /home/microcut/shared" (in directory "/home/microcut"): error=2, No such file or directory)

I am assuming this error has something to do with the working directory. But no matter how I define the working directory, I cannot get the program to run without an error. The working directory is valid, otherwise allot of my other code the relieson this directory definition would not be working.

Can anyone point me in a proper direction here?


Active Member
I was able to get the network drive mounted programmatically, but not in a way that I thought was going to work, hopefully the following may help or point someone else in the proper direction and if someone has any suggestions (someone a lot smarter than me in the Linux world) I will be appreciative.

I tried Erel's suggestions to use the Run without the RunWithOutoutEvents, this did not work.
I then tried Erel's other suggestion, by removing the Sudo statement, and this did not work either.

How I solved the problem - at least, one way I guess. There are probably other ways to. There are a lot of smart people on this forum.

If I only used the command mount in the shell command, I was able to get an output in the log, of what was currently mounted. So at least I knew the mount command would run from the Jshell. I then tried to parse the command, by adding a string array of the extra statements, thinking the issue may be a parsing problem, but this was a dead end.

I then created a bash script, which I tested in terminal mode, and it worked fine. I was thinking of the parsing of such a long command line, that maybe the Jshell was not handling this properly and using a bash script would be successful. Unfortunately I got the same results.

I did not understand what was going on here, why Jshell was always telling I had a directory or file error??

I then realized that I was also using the Jshell command successfully for calling a touch screen calibration program. The difference here was the touch screen calibration program was not sitting in my home directory, but in the file system directory /user/local/egalaxytouch.

So I copied the bash script as administrator to /usr/local/bin directory (could have made up a new one, but it was there, so why not use it.).
Lo and behold, this worked. Success, maybe.

The mount of the network drive has to be user defined, and I did not know, if I created the bash script with user input, whether (1) it would save properly to a filesystem directory and (2) if it would then run. So I created a quick test program to generate a bash script, then save it to /usr/local/bin and the set the file to executable.

Sample code block:
File.WriteString("/usr/local/bin","net1.sh","sudo -S mount -t cifs -w -o username=service -o password=service // /home/microcut/mnt/shared")

Private jf As FileWatcher

shl.WorkingDirectory = "/usr/local/bin/"

This worked fine, so all I will need to do in the future is create a small input program for the user, to get the username, password, server/workstation IP address and directory.
And substitute those values.

So hopefully this may help someone else, and I am sure that even though this works, there are probably better ways to do this, if anyone knows, just post your thoughts.
Upvote 0