Hi,
I tried using execProcess, execCmd and execShellCmd to execute a system command on windows OS, I compile my code with --app:gui ( also tried using winim FreeConsole()), whenever a command is executed a cmd prompt flashes briefly , Is there a way to avoid it ?
Try
import osproc
echo exec_cmd_ex("ls -ax").output
On Windows you can use the winim package, specifically winim/com, for this purpose.
Exemple:
import winim/com
const cmd = "cmd.exe /c ping 127.0.0.1"
comScript:
var a = CreateObject("WScript.Shell")
echo "Executing command, waiting to finish and showing the window..."
discard call(a, "Run", toVariant(cmd), toVariant(1), toVariant(true))
echo "Executing command, waiting to finish and not showing the window..."
discard call(a, "Run", toVariant(cmd), toVariant(0), toVariant(true))
echo "Executing command, without waiting to finish and showing the window..."
discard call(a, "Run", toVariant(cmd), toVariant(1), toVariant(false))
echo "Executing command, without waiting to finish and not showing the window..."
discard call(a, "Run", toVariant(cmd), toVariant(0), toVariant(false))
Ok I found the solution
I was using:
var output = execProcess("cmd.exe /c ipconfig")
Which caused the console to flash when app is compiled with --app:gui
when changed to:
var output = execProcess("cmd.exe /c ipconfig" , options={poUsePath, poStdErrToStdOut, poEvalCommand, poDaemon})
It solved the issue.
Thank everyone!