Try to create an interface (windows ui) witth b4j but i need to execute also cmd commands.
I am new with b4j. How can i do that. I come up with jShell but there is no working example.
Hi stp, use the keyword "jshell" in the forum's search engine and you will be presented with many related threads! I'm sure one of them will send you in the right path!
Sub Class_GlobalsPrivate Root As B4XViewPrivate xui As XUIEndSub
Public Sub Initialize' B4XPages.GetManager.LogEvents = TrueEndSub'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created(Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
EndSub'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click'xui.MsgboxAsync("Hello world!", "B4X")Dim shl As Shell
shl.Initialize("shl", "calc.exe", Null)
'shl.WorkingDirectory = "C:\Program Files\iA Writer"
shl.WorkingDirectory = "\"
shl.Run(-1)
'StartMessageLoop 'need to call this as this is a console app.EndSub
but i want ro run cmd commands, not windows executables.
Eg i want to execute an ffmpeg cmd command with parameters or a winzip command with parameters.
Do i have to open a cmd ?
Hi stp, use the keyword "jshell" in the forum's search engine and you will be presented with many related threads! I'm sure one of them will send you in the right path!
Hi stp, use the keyword "jshell" in the forum's search engine and you will be presented with many related threads! I'm sure one of them will send you in the right path!
You can add the correct arguments for the command you want to use to the array.
The java command is an example of that.
Can you show the command line (as you would type it at the command prompt)?
You can add the correct arguments for the command you want to use to the array.
The java command is an example of that.
Can you show the command line (as you would type it at the command prompt)?
You might find this useful: NOTE: I was NEVER able to make this work with a long string with all of the parameters, I had to use params.Add and the batch file.
B4X:
Public Sub OpenJobInSk2010(JobNum As String)
TryIf JobNum.Length = 0ThenReturnDim L As List = File.ReadList($"${File.DirApp}\.."$, "AccessCmdLine.txt")
Dim SKPth As String = $"${File.DirApp}\..\${L.Get(2)}"$Dim AccPth As String = L.Get(1)
Private shl As ShellDim params As List: params.Initialize
'params.Add("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE") 'for testing
params.Add($""${AccPth}""$)
params.Add($""${SKPth}""$)
params.Add("/Runtime")
params.Add(" /nostartup")
params.Add("/CMD" )
params.Add($"${JobNum} *\\* ${L.Get(0)}"$)
shl.Initialize("shl", $""${File.DirApp}\..\AccessCmdLine.bat""$, params)
shl.WorkingDirectory = File.DirApp
shl.Run(-1)
SetForegroundWindow("ShopKeeper Job Control", False)
CatchLog(LastException)
Main.Msgbox.Show(LastException.Message.SubString2(0, Min(LastException.Message.Length, 500)), "OpenJobInSk2010")
EndTryEndSub
A little explanation:
This opens an MS Access program, opens a particular form and navigates to a particular job.
AccessCmdLine.txt is written by the Access program when it opens my B4J program. It tells the B4J program where to find msaccess.exe and where to find the access program (AccPth, SKPth).
AccessCmdLine.bat is just the following:
B4X:
start /min %1 %2 %3 %4 %5 %6
And here is the code for SetForegroundWindow, note that you must know the EXACT title of the window for this to work:
B4X:
Sub SetForegroundWindow(Title As String, JustFind As Boolean) As BooleanReturnMe.As(JavaObject).RunMethod("SetForegroundWindow", Array(Title, JustFind))
EndSub
Hope this helps
#if Java
import com.sun.jna.platform.win32.*;
public static boolean SetForegroundWindow(String title, boolean justFind) {
User32 user32 = com.sun.jna.platform.win32.User32.INSTANCE;
for (com.sun.jna.platform.DesktopWindow s : com.sun.jna.platform.WindowUtils.getAllWindows(false)) {
String t = s.getTitle();
if (t.toLowerCase().equals(title.toLowerCase())) {
if (!justFind) {
user32.SetForegroundWindow(s.getHWND());
user32.SetFocus(s.getHWND());
user32.ShowWindow(s.getHWND(), 9);
}
return true;
}
}
return false;
}
#End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.