RunProgram bug or missing?

Just starting out? Need help? Post your questions and find answers here.
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

RunProgram bug or missing?

Post by Fredi »

Hi

Why ShellExecute in this code work perfect:

Code: Select all

ShellExecute_(0,"open","cmd.exe","/c c:\test.exe > output.txt","c:\",#SW_HIDE)
(cmd is hide and output true)


But PB RunProgram:

Code: Select all

RunProgram("cmd.exe","/c " + "c:\test.exe" + " > output.txt" ,"c:\" ,#PB_Program_Hide)
(cmd is visible and output = Null )


Its bug or something is missing? i know about ReadProgramString but i want know why this doesn't work !
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

RunProgram <> shellexecute!

RunProgram uses for files, not for executable, shellexecute.
For executable it uses createprocess api
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

RunProgram bug or missing?

Post by Fredi »

Thanks ts-soft for info, now if i used shellexecute to run an program how can i wait until program closed? something like #PB_Program_Wait in RunProgram ?
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

RunProgram bug or missing?

Post by Wolf »

ts-soft wrote: RunProgram uses for files, not for executable...
Are you sure ts-soft? RunProgram as it say must be for programs not files.... anyway may be my mistake.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

try yourself:
call RunProgram with e.g. a textfile as argument.
oh... and have a nice day.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: RunProgram bug or missing?

Post by ts-soft »

Wolf wrote:
ts-soft wrote: RunProgram uses for files, not for executable...
Are you sure ts-soft? RunProgram as it say must be for programs not files.... anyway may be my mistake.
You have misunderstood, the underlaying API call, if you use RunProgram is
not always the same.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

RunProgram bug or missing?

Post by Wolf »

After some test now better understand your mean, thanks :wink:

@Fredi
You can use ShellExecuteEx, this is a example:

Code: Select all

  ei.SHELLEXECUTEINFO
  ei\cbSize = SizeOf(SHELLEXECUTEINFO)
  ei\fMask = #SEE_MASK_FLAG_DDEWAIT | #SEE_MASK_NOCLOSEPROCESS
  ei\nShow = #SW_HIDE
   
  ei\lpVerb = @"open"
  ei\lpFile = @"cmd"
  ei\lpParameters = @"/c dir"
  ei\lpDirectory = @"c:\"
           
  Result = ShellExecuteEx_(@ei)
           

    For i = 1  To 300
       Delay(1000)  ;check for 300*1000ms if ShellExecute is done
       If GetExitCodeProcess_(ei\hprocess, @ExitCode)
         If ExitCode <> #STILL_ACTIVE
           Break
         EndIf
       EndIf
    Next
             
    If ExitCode<>#STILL_ACTIVE
      Debug Str(ExitCode) ;Exit code of external app
    Else
     Debug "Timeout" ;ShellExecute still not finished
    EndIf       
Post Reply