Recent

Author Topic: [SOLVED] Keeping TProcess' console window open  (Read 2509 times)

iyugov

  • New member
  • *
  • Posts: 8
[SOLVED] Keeping TProcess' console window open
« on: August 01, 2018, 01:05:31 pm »
Is there a cross-platform (Linux/Windows) way to launch a TProcess in a console and keep its window open after it terminates?
I think I could use $ifdef-s and start the launch command with "sh -c"/"cmd.exe /k" but it is not simple and not uniform.
« Last Edit: August 06, 2018, 06:53:16 am by iyugov »

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Keeping TProcess' console window open
« Reply #1 on: August 01, 2018, 04:09:46 pm »
No. Under Windows, you need to call cmd.exe. And under Linux, you need to call terminal emulator of your choice e.g roxterm with appropriate command line options.

iyugov

  • New member
  • *
  • Posts: 8
Re: Keeping TProcess' console window open
« Reply #2 on: August 04, 2018, 10:59:00 pm »
I did it with cmd.exe/sh. My procedure creates .bat/.sh file with four lines -
1) echo Start
2) cmd.exe /c command_string (or sh -c command_string)
3) echo End
4) read line
and executes it. The structure of the call is always the same:
 - the executable is cmd.exe/sh;
 - 1st parameter is /c or -c;
 - next parameters are in command_string.
It works.
And it makes another problem. Command_strings are configurable by the user. They may contain spaces, quote characters etc. Here their parsing is up to the command-line interpreter. But I also need the ability to execute the same command_strings without delays and console windows, directly, without .bat/.sh files. I need uniform parsing. For direct execution, I use Process.Executable with Process.Parameters and CommandToList to parse command_string. But CommandToList has its own parsing rules, and I cannot rewrite it for identical results with command-line interpreters. Should I use Process.CommandLine instead? (it's deprecated).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: Keeping TProcess' console window open
« Reply #3 on: August 04, 2018, 11:06:37 pm »
Don't work with commandlines, but with separate arguments in a list

If some system requires a commandline, combine them using uniform rules.

Such separate-to-oneline rules are much simpler than the other way around, which is why the commandline property was deprecated (there were constant other interpretations and features, and new features broke old behaviour on other OSes)

iyugov

  • New member
  • *
  • Posts: 8
Re: Keeping TProcess' console window open
« Reply #4 on: August 06, 2018, 06:51:30 am »
The soultion was quite simple.
I wrote a special console launcher. It takes the command string from the main application as a single parameter, uses the same procedure with my rules to parse it to Executable and Parameters, then executes it with necessary echos and delays. Command-line interpreters are not used anymore.
« Last Edit: August 06, 2018, 06:53:04 am by iyugov »

 

TinyPortal © 2005-2018