B4J Question Shell command running on background

Toley

Active Member
Licensed User
Longtime User
I have finally managed to start a console app and send parameters to it with the jShell library. My question is if it is possible to run the process in background, I mean without opening the DOS window?
 

jmon

Well-Known Member
Licensed User
Longtime User
I'm not sure I understand correctly.

If you don't call the MainForm.Show method, the window won't be visible.
Otherwise you can make a non-ui app by clicking File>New>Non-UI

Once you compile your app in Release mode, you can open your jar file in the objects folder, and there won't be any DOS window appearing.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you don't call the MainForm.Show method, the window won't be visible.
He want to start a dos app but dont want to popup/show the DOS-Command window
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
on windows you can do the following:
  1. Create the windows Script Host file - test.vbs - and save it in DirApp folder:
    B4X:
    Dim WinScriptHost
    Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "mybatch.bat" & Chr(34), 0
    Set WinScriptHost = Nothing
  2. create a batch file, containing your DOS commands - mybatch.bat - and save it in DirApp folder:
    B4X:
    copy a.txt b.txt
  3. use the B4J shell like this:
B4X:
  Private shl As Shell
  Dim params As List: params.Initialize
  params.Add("/c")
  params.Add("start")
  params.Add("test.vbs")   
  shl.Initialize("shl", "cmd.exe", params)
  shl.WorkingDirectory = File.DirApp
  shl.Run(-1)

this will run mybatch.bat without a DOS window...may be there are more elegant solutions...
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
When I call dos commands, I don't get a dos window popping up. For example the "Dir" command (http://ss64.com/nt/dir.html) I call it this way:
B4X:
Dim sh As Shell
sh.Initialize("Shell", "cmd.exe", Array("/c", "dir"))
sh.Run(1000)
 
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
When I call dos commands, I don't get a dos window popping up. For example the "Dir" command (http://ss64.com/nt/dir.html) I call it this way:
B4X:
Dim sh As Shell
sh.Initialize("Shell", "cmd.exe", Array("/c", "dir"))
sh.Run(1000)

Hi ,
"/c" Carries out the command specified by string and then terminates,
I use cmd a lot but i did not seen it popping up either might be too fast regardless of sh.run(1000)
 
Upvote 0

Toley

Active Member
Licensed User
Longtime User
Sorry I probably did not explain correctly what I want to do. I'm working on a B4J UI app that is connected to a microcontroller by UART. I have a bootloader on the MCU and I want to reprogram the MCU via the B4J app (and this is actually working). I'm using ds30Loader bootloader.

Here is how I start it:
B4X:
Sub RunShellCommand
      'ds30LoaderConsole must be in objects folder!
    Private shl As Shell
    Private params As List
    params.Initialize
    params.Add("/c")
    params.Add("start")
    params.Add("ds30LoaderConsole.exe") 'located in File.DirApp
    params.Add("-f="&fname)                'fname is the full path of the hex file. TODO change it for File.DirApp
    params.Add("-d=pic16f1825")            'device
    params.Add("-k=com14")                'COM Port
    params.Add("-r=115200")                'Baudrate
    params.Add("-p")                    'write flash
    params.Add("-o")                    'non-interactive
    shl.Initialize("shl","cmd.exe",params)
    shl.WorkingDirectory = File.DirApp
    Try
        ' Run with disabled timeout
          shl.Run(-1)
      Catch
        Log(LastException.Message)
      End Try
End Sub

I just want to hide the magic and do not show the DOS window. But I can live with it, ds30Loader is fully free and can be used or modified at will.
 
Upvote 0
Top