Very grateful for your attention and your answers to solve the following:
I need to run a bat file, from XOJO
When I run it manually, the DOS command window is displayed, with the execution sentences of the file
I tried it with the following code, but the DOS command window is NOT shown, with the execution sentences of the file
Dim s As Shell
s=New Shell
s.Mode = 2
s.Execute("C:\\WINDOWS\\system32\\cmd.exe,C:\\SFS_v1.3.1\\EjecutarSFS.bat")
If s.errorCode > 0 then
MsgBox "Error code: " + Str(s.errorCode)
End if
Under Windows, you need a couple of additional entries:
Dim s As Shell
s=New Shell
s.Mode = 2
// without setting the timeout value on Windows, the shell exits after 2 seconds
// regardless of whether the shelled task actually completed.
s.Timeout = -1
s.Execute("C:\\WINDOWS\\system32\\cmd.exe,C:\\SFS_v1.3.1\\EjecutarSFS.bat")
// You need to wait for the shell to complete what you've told it to do
Do
s.poll
Loop Until Not s.IsRunning
If s.errorCode > 0 then
MsgBox "Error code: " + Str(s.errorCode)
End if
To test, I tried to run the cmd.exe command, but I get NO result.
any ideas?
The code is the following:
Dim ArchivoExe As string
s.Mode = 1
s.TimeOut=-1
ArchivoExe="C:\\Windows\\System32\\cmd.exe"
s.Execute(ArchivoExe)
Do
s.Poll
Loop Until Not s.IsRunning
If s.errorCode > 0 then
MsgBox "Error code: " + Str(s.errorCode)
End if
All that you did there was to launch a new cmd.exe shell terminal. It will run forever. You need to actually run the .bat file in the s.Execute step.
For example:
[code] Dim ArchivoExe As string
Dim theResult(-a) As String
Dim s As New Shell
s.Mode = 1
s.TimeOut=-1
ArchivoExe=“DIR /s C:\Windows\System32”
s.Execute(ArchivoExe)
Do
s.Poll
Loop Until Not s.IsRunning
If s.errorCode > 0 then
MsgBox "Error code: " + Str(s.errorCode)
Else
theResults = SplitB(ReplaceLineEndings(s.ReadAll, EndOfLine), EndOfLine)
End if
// now use the results from the DIR command by parsing the elements of theResult()
[/code]
Dim archivobat As string
archivobat="START C:\\SFS_v1.3.1\\archivonuevo.bat"
Dim s As Shell
s=New Shell
s.Mode = 2
s.Timeout = -1
s.Execute(archivobat)
Do
s.poll
App.DoEvents(5)
Loop Until Not s.IsRunning
s.Write(archivobat)
If s.errorCode > 0 then
MsgBox "Error code: " + Str(s.errorCode) + EndofLine + EndOfLine + s.Readall
Else
MsgBox "Ejecucion correcta "
End if