Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-10

Run process and exit (win32)

8 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ram�

Hi, I'm trying to start a Win32 process and exit leaving the process executing. The test scenario is a CGI calling a simple Http server (the Synapse Http server demo).

The problem is the CGI program doesn't stop (in Firefox's status bar there's a "Transfering data from localhost..." message until I click Stop button) until the child process is finished. If I refresh the page, the program works as expected.

Any hint on this?

To start the child process I use TProcess as follows:

...
    lProcess := TProcess.Create(nil);
    try
      lProcess.CommandLine := 'httpserver.exe';
      lProcess.Options := [poNoConsole];
      lProcess.Execute;
    finally
      lProcess.Free;
    end;
...

Leonardo M. Ramé
http://leonardorame.blogspot.com

__________________________________________________ Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Reply by email

ik
to Leonardo M. Ram�

"Execute" is blocking, so it will continue to execute itself until you will stop the execution.

You might wish to seperate the process by creating two executables, and execute a program in the background so you could decide what to do, like in a daemon way...

Ido

Leonardo M. Ramé wrote 36 lines
Hi, I'm trying to start a Win32 process and exit leaving the process executing. The test scenario is a CGI calling a simple Http server (the Synapse Http server demo). The problem is the CGI program doesn't stop (in Firefox's status bar there's a "Transfering data from localhost..." message until I click Stop button) until the child process is finished. If I refresh the page, the program works as expected. Any hint on this? To start the child process I use TProcess as follows: ... lProcess := TProcess.Create(nil); try lProcess.CommandLine := 'httpserver.exe'; lProcess.Options := [poNoConsole]; lProcess.Execute; finally lProcess.Free; end; ... Leonardo M. Ramé http://leonardorame.blogspot.com __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Leonardo M. Ram�
to ik
You might wish to seperate the process by creating two executables,

That's already done.

and execute a program in the background so you could decide what to do, like in a daemon way...

Yes, the problem is I want to do it in a multiplatform way.

In Linux I can set CommandLine := 'httpserver &';
In Win32 I should create a service, *but* I don't have administrative privileges.

Correct me if I'm wrong, can I create a Win32 service without admin privileges? Or do you know a better way?

--- ik wrote 56 lines
"Execute" is blocking, so it will continue to execute itself until you will stop the execution. You might wish to seperate the process by creating two executables, and execute a program in the background so you could decide what to do, like in a daemon way... Ido On 10/23/07, Leonardo M. Ramé wrote: > Hi, I'm trying to start a Win32 process and exit leaving the process executing. The test scenario > is a CGI calling a simple Http server (the Synapse Http server demo). > > The problem is the CGI program doesn't stop (in Firefox's status bar there's a "Transfering data > from localhost..." message until I click Stop button) until the child process is finished. If I > refresh the page, the program works as expected. > > Any hint on this? > > To start the child process I use TProcess as follows: > > ... > lProcess := TProcess.Create(nil); > try > lProcess.CommandLine := 'httpserver.exe'; > lProcess.Options := [poNoConsole]; > lProcess.Execute; > finally > lProcess.Free; > end; > ... > > > > > Leonardo M. Ramé > http://leonardorame.blogspot.com > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -- http://ik.homelinux.org/ > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

__________________________________________________ Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Reply by email

Leonardo M. Ram�
to L: did. Something like this below: program ShellExec; {$mode objfpc}{$H+} uses pwumain,…
Show quoted text 14 lines
program ShellExec; {$mode objfpc}{$H+} uses pwumain, windows; begin WebWriteln(' Hello! '); ShellExecute(0 , 'open', 'cmd /k c:\winnt\notepad.exe', nil, nil, SW_SHOWNORMAL) ; end. Because cmd /k forks open a new separate cmd shell for you (not a child, AFAIK). But test it, and let me know.

Thanks L, do you know if I ShellExecute can create a process without showing the command window?

__________________________________________________ Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Reply by email

L
Show quoted text 5 lines
> Hi, I'm trying to start a Win32 process and exit leaving the process > executing. The test > scenario > is a CGI calling a simple Http server (the Synapse Http server demo). >I have done this before but it has been months and I forget exactly what I

did.

Something like this below:

program ShellExec; {$mode objfpc}{$H+}
uses
  pwumain, windows;
begin
  WebWriteln(' Hello! ');
  ShellExecute(0 , 'open', 'cmd /k c:\winnt\notepad.exe', nil, nil,
SW_SHOWNORMAL) ;
end.

Because cmd /k forks open a new separate cmd shell for you (not a child, AFAIK). But test it, and let me know.

Then on unix you already know how with the ampersand, so just make a cross platform wrapper.

I have not looked at TProcess source code and don't know if it will work for you.. but maybe we can patch TProcess to give it some new abilities if it cannot launch a separate process currently?

Reply by email

L
Thanks L, do you know if I ShellExecute can create a process without showing the command window?

I'm sure you can hide it.. just a matter of finding the right Windows API paramaters..

Probably something like..
SW_HIDE

Not tested, not sure. ;-)

Reply by email

L
Show quoted text 13 lines
> Thanks L, do you know if I ShellExecute can create a process without showing > the command window? I'm sure you can hide it.. just a matter of finding the right Windows API paramaters.. Probably something like.. SW_HIDEy Not tested, not sure. ;-)

Actually, maybe cmd /c will help you too (or not)

Syntax
cmd [[{/c|/k}] [/s] [/q] [/d]
[{/a|/u}] [/t:fg]
[/e:{on|off}] [/f:{on|off}]
[/v:{on|off}] string]

Parameters
/c : Carries out the command specified by string and then stops. /k : Carries out the command specified by string and continues. /s : Modifies the treatment of string after /c or /k. /q : Turns the echo off.
/d : Disables execution of AutoRun commands.
/a : Creates American National Standards Institute (ANSI) output. /u : Creates Unicode output.
/t:fg : Sets the foreground f and background g colors. The following tables lists valid hexadecimal digits that you can use as the values for f and g.

Reply by email

L

Have you tested this simple way of doing it below

program test; {$mode objfpc} {$H+}
uses windows;
begin
  ShellExecute(0 , 'open', 'notepad', nil, nil, SW_SHOWNORMAL) ;
  ShellExecute(0 , 'open', 'notepad', nil, nil, SW_HIDE) ;
end.

The cmd /k may not even be needed... and it may not even work the way I showed in the previous examples in my emails.

Reply by email