B4J Question cmd shell on windows

klingon467

Member
Licensed User
Longtime User
hi!
i want to pass this command:
B4X:
jar uvf dwn.jar Files/settings.txt


my code:
B4X:
Sub btnADD_Action
Try
    sh.Initialize("sh", "jar uvf dwn.jar Files/settings.txt", Null)
    sh.WorkingDirectory = File.DirApp
    sh.Run(-1)
                Catch
    Log(LastException.Message)
   
    End Try
End Sub
Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success AND ExitCode = 0 Then
     Log("Success")
     Log(StdOut)
   Else
     Log("Error: " & StdErr)
   End If
   ExitApplication

End Sub
not work exception:
Error: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "jar uvf dwn.jar Files\settings.txt" (in directory "D:\Desktop\_SRC_B~1\_B4J_D~1\Objects"): CreateProcess error=2, Impossibile trovare il file specificato)

????
thanks
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Does this code execute from within dwn.jar? If you are trying to modify a currently running .jar file, you might run into problems with Windows forbidding write access to the .jar file.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

suggest to use parameter list for the call jar uvf dwn.jar Files/settings.txt

B4X:
Dim args As List
args.Initialize
args.Add("-uvf")
args.Add("dwn.jar")
args.Add("Files/settings.txt")
sh.Initialize("sh", "jar", args)

Ensure the path to jar.exe is set, else init with some like below:
B4X:
sh.Initialize("sh", """c:\Program Files (x86)\Java\jdk8\bin\jar.exe""", args)
 
Upvote 0

klingon467

Member
Licensed User
Longtime User
Hi,

suggest to use parameter list for the call jar uvf dwn.jar Files/settings.txt

B4X:
Dim args As List
args.Initialize
args.Add("-uvf")
args.Add("dwn.jar")
args.Add("Files/settings.txt")
sh.Initialize("sh", "jar", args)

Ensure the path to jar.exe is set, else init with some like below:
B4X:
sh.Initialize("sh", """c:\Program Files (x86)\Java\jdk8\bin\jar.exe""", args)

thank you very much
work perfectly! :D
 
Upvote 0
Top