B4J Question Execute command line orden using B4J jshell in LINUX

Luis Felipe Andrade

Member
Licensed User
Hello, I am trying to execute a command (date) contained in an executable batch file, this file must be executed to correct the time on Linux computers since the automatic and manual time are modified from time to time, so from my jar file I send the instruction to create the file with the correct time that I get from my server, and I need to execute the command 'sudo date -s 'Correct date and time' but with jshell the batch file is not executed. The file has +x execution permissions, if I run it from the terminal it makes the modification on system, I hope you can help me. thank you so much.

My Code Is::
Dim TextWriter1 As TextWriter
TextWriter1.Initialize( File.OpenOutput( File.DirApp , "lahora.sh",  False))
TextWriter1.WriteLine("sudo date -s '" &  pday & " " & pmonth & " " & pyear & " " & phour & ":" & pminut & ":" & "00'")
TextWriter1.Close
Dim shl As Shell
shl.Initialize("shl", "lahora.sh", Null)
shl.WorkingDirectory = "/home/schuser/kalisys"
shl.Run(-1)
 

aminoacid

Active Member
Licensed User
Longtime User

So are you saying you code above does not work? If so, please explain what's happening. Do you get an error message? Nothing happens? need more details. Use:

Wait For shl_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)

after shl.run and examine the returned variables - success, stdOut, etc.

Also, I noticed that you are creating the "lahora.sh" file in your code but you are not giving it the "+x" attribute. So there's no way that it's going to execute. You need to initiate another shl run with the command chmod +x lahora.sh before you execute it.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…