Running a bat file

Windows specific forum
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Running a bat file

Post by Trond »

No matter what I do it opens its own console window!

Code: Select all

OpenConsole()
Delay(500)

; RunProgram("c:\test.bat") (works)

ShellExecute_(0, "open", "c:\test.bat", "", "", #SW_NORMAL)

Delay(500)
The bat file:

Code: Select all

@echo Hello from %0
@pause

Max
User
User
Posts: 67
Joined: Thu Nov 30, 2006 4:57 pm
Location: I long for the absolute loneliness of the death

Post by Max »

Have you tried to compile with /console option?.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Yes.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

http://www.purearea.net/pb/english/manu ... ogram.html

Code: Select all

RunProgram(FileName$, Parameter$, WorkingDirectory$, #PB_Program_Hide )
:?:
--Kale

Image
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Kale wrote:http://www.purearea.net/pb/english/manu ... ogram.html

Code: Select all

RunProgram(FileName$, Parameter$, WorkingDirectory$, #PB_Program_Hide )
:?:
He would like it to redirect the input. And he don't want to use runprogram [which does redirect the input if you are compiling using /console option]
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Kale wrote:http://www.purearea.net/pb/english/manu ... ogram.html

Code: Select all

RunProgram(FileName$, Parameter$, WorkingDirectory$, #PB_Program_Hide )
:?:
The RunProgram() in the code in the first post works, but I want to figure out how to do it using API. I'd like the output from the bat file inside my console window, not hidden.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Around a year ago there was a similar thread, but damned if I can find it now. You want the output of the batch sent to your console window instead of opening its own new one, right? That's what the thread dealt with and it was solved, so it's a matter of finding it.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

netmaestro wrote:You want the output of the batch sent to your console window instead of opening its own new one, right?
Yes.
Edit: I found something like that, but it uses RunProgram().
Edit: WinExec_("c:\test.bat", 0) works, but is deprecated.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Works:

Code: Select all

OpenConsole()
GetStartupInfo_(@si.STARTUPINFO)
pi.PROCESS_INFORMATION
CreateProcess_("c:\test.bat", "", 0, 0, 1, 0, 0, 0, @si, @pi)
WaitForSingleObject_(pi\hProcess, 10000)
I still don't understand why ShellExecute_() doesn't work though.
Post Reply