B4J Question Starting the batch file without calling the window?

T201016

Active Member
Licensed User
Longtime User
Hi,
I use the following command in the batch file, which opens the command window unnecessarily.
I know that the command "Hidecommandwindow" closes the command window, but it does not affect me.
What other command could I use?

@echo off
HideCommandWindow
C:\Windows\System32\cmd.exe /c start D:\ffmpeg\bin\ffmpeg.exe {...}
 
Solution
This seems to work (except that it runs sleep.exe instead of ffmpeg.exe) :

B4X:
Sub Button1_Click
    Log("Click start")
    
    Dim batchfile As List
    batchfile.Initialize

    batchfile.Add("@echo off")
    batchfile.Add("break on")
    batchfile.Add("")
    batchfile.Add("e:")
    batchfile.Add("cd \util")
    batchfile.Add("echo before")
    batchfile.Add("echo. | time")
    batchfile.Add("start /low /min /affinity 1 /wait sleep 20")
    batchfile.Add("echo. | time")
    batchfile.Add("echo after")

    File.WriteList(File.DirTemp, "custom.bat", batchfile)
        
    Dim cmd As String = File.dirtemp & "\custom.bat"
    cmd = cmd.Replace("\\", "\")
    
    Log(cmd)
    
    Sh.Initialize("ShellEvent", "cmd.exe", Array As...

emexes

Expert
Licensed User
Longtime User
What other command could I use?

You could try the jShell library:

https://www.b4x.com/b4j/help/jshell.html

1758903592670.png

1758904123331.png

1758904139546.png
 
Last edited:
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Hi, @emexes

The problem occurs at the time of adding a fragment of this line: C: \Windows\System32\cmd.exe /c start /affinity 3
Because I want FFMPEG to start on the selected CPU core. Without this added fragment, everything works OK.
I tried to insert this fragment into the start_cmd function but to no avail.
What should shl initialize's initiation look like with the "cmd.exe /c start /affinity 3" parameter?

B4X:
Dim script As String = File.Combine(File.DirApp, "\Scripts\Script_converting.cmd")

start_cmd(script & " 3 " & media & " " & mp4) 'Windows command script (with command interpreter 'cmd.exe')

Private Sub start_cmd(fScript As String)
    shl.Initialize("shl", "cmd.exe", Array As String("/c", fScript))
    shl.WorkingDirectory = Dialog.Target
    shl.RunSynchronous(-1)
End Sub

A fragment of the batch file in which the start of CMD.EXE causes the window to open:
C:\Windows\System32\cmd.exe /c start /affinity 3 D:\ffmpeg\bin\ffmpeg.exe -i %2 -s 960x540 -c:v libx264 -b:v 1260k -r 24 -x264opts keyint=48:min-keyint=48:no-scenecut -profile:v main -preset ultrafast -movflags +faststart -c:a libfdk_aac -b:a 192k -ac 2 -threads 2 %3
 
Last edited:
Upvote 0

T201016

Active Member
Licensed User
Longtime User
I have a headache:mad:, I'm tired and also lazy, so much so that I don't even translate (I guess you have Chrome anyway):

https://chatgpt.com/c/68d7ab8b-6564-8333-b3ca-922f7b9585fa
Hi @LucaMs :)
Ha ha 🙂 ChatGPT told me as much as I already know. I thought that since there was a method of launching cmd.exe with an option /min, I thought naively that there is also an option /hide 🙂

I will probably be able to create a .vbs file and run it via Shell, I think it will work. Thank you all for the hints to date...
PS. Unable to load conversation ???
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
This seems to work (except that it runs sleep.exe instead of ffmpeg.exe) :

B4X:
Sub Button1_Click
    Log("Click start")
    
    Dim batchfile As List
    batchfile.Initialize

    batchfile.Add("@echo off")
    batchfile.Add("break on")
    batchfile.Add("")
    batchfile.Add("e:")
    batchfile.Add("cd \util")
    batchfile.Add("echo before")
    batchfile.Add("echo. | time")
    batchfile.Add("start /low /min /affinity 1 /wait sleep 20")
    batchfile.Add("echo. | time")
    batchfile.Add("echo after")

    File.WriteList(File.DirTemp, "custom.bat", batchfile)
        
    Dim cmd As String = File.dirtemp & "\custom.bat"
    cmd = cmd.Replace("\\", "\")
    
    Log(cmd)
    
    Sh.Initialize("ShellEvent", "cmd.exe", Array As String("/c", cmd)) ' Example command: dir
    Sh.Run(-1) ' Run the command with no timeout (-1)
    
    Log("Click done")
End Sub

Sub ShellEvent_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log("ProcessCompleted: " & Success & TAB & ExitCode)
    Log(StdOut)
End Sub
Log output:
Waiting for debugger to connect...
Program started.
Click start
C:\Users\emexe\AppData\Local\Temp\custom.bat
Click done
ProcessCompleted: true    0
before
The current time is:  1:27:12.47
Enter the new time: 
The current time is:  1:27:32.73
Enter the new time: 
after
 

Attachments

  • TestShellNoWindow.zip
    2.5 KB · Views: 1
Upvote 0
Solution

T201016

Active Member
Licensed User
Longtime User
This seems to work (except that it runs sleep.exe instead of ffmpeg.exe) :

B4X:
Sub Button1_Click
    Log("Click start")
   
    Dim batchfile As List
    batchfile.Initialize

    batchfile.Add("@echo off")
    batchfile.Add("break on")
    batchfile.Add("")
    batchfile.Add("e:")
    batchfile.Add("cd \util")
    batchfile.Add("echo before")
    batchfile.Add("echo. | time")
    batchfile.Add("start /low /min /affinity 1 /wait sleep 20")
    batchfile.Add("echo. | time")
    batchfile.Add("echo after")

    File.WriteList(File.DirTemp, "custom.bat", batchfile)
       
    Dim cmd As String = File.dirtemp & "\custom.bat"
    cmd = cmd.Replace("\\", "\")
   
    Log(cmd)
   
    Sh.Initialize("ShellEvent", "cmd.exe", Array As String("/c", cmd)) ' Example command: dir
    Sh.Run(-1) ' Run the command with no timeout (-1)
   
    Log("Click done")
End Sub

Sub ShellEvent_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log("ProcessCompleted: " & Success & TAB & ExitCode)
    Log(StdOut)
End Sub
Log output:
Waiting for debugger to connect...
Program started.
Click start
C:\Users\emexe\AppData\Local\Temp\custom.bat
Click done
ProcessCompleted: true    0
before
The current time is:  1:27:12.47
Enter the new time:
The current time is:  1:27:32.73
Enter the new time:
after
Your example has also confirmed my similar attempts with the .VBS - thank you very much 👍
 
Upvote 0
Top