View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0022302FPCFCLpublic2012-06-22 13:532013-01-07 17:05
Reporterdusan.halicky 
Assigned ToMichael Van Canneyt 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version2.4.2Product Build 
Target VersionFixed in Version 
Summary0022302: Add option to TProcess to hold console after process is finished
DescriptionThere is poNewConsole in TProcess.Options. But when I execute something that finish very fast I don't see what it was. I use it on both linux and windows and I managed to modify process.pas/.inc to suit my needs. I added new option poHoldConsole and when this option is set, on linux I add "-hold" parameter to xterm, and on windows I prepend "cmd /K " before TProcess.CommandLine. Both modifications are in attachment.

Modified lines for linux version:

  if poHoldConsole in P.Options then
    S.Insert(0,'-hold');

Modified lines for windows version:

  if (poHoldConsole in Options)and(FCommandLine <> '') then
    FCommandLine := 'cmd.exe /K '+FCommandLine;

As you can see, it is quite simple. I'm not sure if there are some other problems with this solution. Full source is in attachment.
Steps To Reproduce// source for modified TProcess for linux and windows is in attachment

p := TProcess.Create;
p.Options := p.Options + [poNewConsole, poHoldConsole];
p.CommandLine := 'echo Hello';
p.Execute;
TagsNo tags attached.
FPCOldBugId
Fixed in Revision
Attached Fileszip file icon process_poHoldConsole.zip [^] (8,240 bytes) 2012-06-22 13:53
zip file icon process-hold-console-diffs.zip [^] (18,796 bytes) 2012-06-25 14:24

- Relationships

-  Notes
(0060657)
Marco van de Voort (manager)
2012-06-23 12:40

Could you generate diffs with the original source you based it on? It would make reviewing a lot easier.
(0060660)
Bart Broersma (reporter)
2012-06-23 16:02

Hardcoding cmd.exe doesn't look OK to me.
(0060672)
dusan.halicky (reporter)
2012-06-25 14:23

To Marco van de Voort:
- I just added diffs in the attachment (process-hold-console-diffs.zip)

To Bart Broersma:
- how is hardcoded cmd.exe different than hardcoded xterm?
- it was the simplest solution for me not knowing details of windows version of process.inc
(0060673)
Marco van de Voort (manager)
2012-06-25 21:50

dusan: I saw.

Anyway on windows ponewconsole isn't handled by cmd.exe at all. On linux afaik the configuration of the shell already allows to add parameters.

The hardcoded xterm is different in that it was already second choice (contrary to do it over API like Windows)

I'm a bit reluctant to make an option over every possible command shell parameter. If you persist in this direction, I think being able to set the shell and its parameters directly is more the way to go than adding po* options for each and every possibility.
(0060675)
dusan.halicky (reporter)
2012-06-26 09:34

Marco: Ok I see. At first I had this code:

p.CommandLine := 'something';

Then I realize i need to run it in new console. So I did this:

{$ifdef windows}
p.CommandLine := 'cmd /C something';
{$endif}
{$ifdef linux}
p.CommandLine := 'xterm -e something';
{$endif}

Then I find out about poNewConsole option and I thought - perfect, I can let TProcess handle the OS abstraction:

p.Options := p.Options + [poNewConsole];
p.CommandLine := 'something';

Then I realized I need to actually see what was written on that console. So I added that poHoldConsole option and it worked. But it seems that now I will have to resort back to ifdefs.

{$ifdef windows}
p.CommandLine := 'cmd /K something';
{$endif}
{$ifdef linux}
p.CommandLine := 'xterm -e -hold something';
{$endif}

Summary: Write once, add some random $ifdef for each platform, then compile anywhere :(

But don't worry, I can live with that.
(0060676)
Ludo Brands (developer)
2012-06-26 10:07

There are many more objections:
-Commandline is deprecated
-The proposed patch is not compatible with the use of ApplicationName
-inserting cmd /k behind the back of the user changes the meaning of ProcessHandle , ThreadHandle and ProcessID. (true for xterm also)
-running an application through cmd /k changes the quoting rules. See the remarks section of http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true. [^]
(0060693)
Bart Broersma (reporter)
2012-06-27 12:46

Using hardcoded cmd.exe will also break Win9x.
(0060703)
barlone (reporter)
2012-06-28 10:43
edited on: 2012-06-28 11:04

Under Windows command processor can be detected from enviroment var COMSPEC.
EDIT: in UNIX from TERM.

(0064724)
Michael Van Canneyt (administrator)
2013-01-07 17:05

As can be seen by the many objections, this is not really a good proposition.

- Issue History
Date Modified Username Field Change
2012-06-22 13:53 dusan.halicky New Issue
2012-06-22 13:53 dusan.halicky File Added: process_poHoldConsole.zip
2012-06-23 12:40 Marco van de Voort Note Added: 0060657
2012-06-23 16:02 Bart Broersma Note Added: 0060660
2012-06-25 14:23 dusan.halicky Note Added: 0060672
2012-06-25 14:24 dusan.halicky File Added: process-hold-console-diffs.zip
2012-06-25 21:50 Marco van de Voort Note Added: 0060673
2012-06-26 09:34 dusan.halicky Note Added: 0060675
2012-06-26 10:07 Ludo Brands Note Added: 0060676
2012-06-27 12:46 Bart Broersma Note Added: 0060693
2012-06-28 10:43 barlone Note Added: 0060703
2012-06-28 11:04 barlone Note Edited: 0060703
2013-01-07 17:05 Michael Van Canneyt Status new => assigned
2013-01-07 17:05 Michael Van Canneyt Assigned To => Michael Van Canneyt
2013-01-07 17:05 Michael Van Canneyt Status assigned => resolved
2013-01-07 17:05 Michael Van Canneyt Resolution open => won't fix
2013-01-07 17:05 Michael Van Canneyt Note Added: 0064724



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker