Recent

Author Topic: Passing parameters to a program with fpSystem open  (Read 1044 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Passing parameters to a program with fpSystem open
« on: October 14, 2019, 04:42:44 pm »
(Mac OS, fpc compiler, not in Lazarus).
What I have now:

        CMD := 'open /Users/alanB/Pascal/cpoper';
        R := fpSystem(CMD);

I'm actually invoking 4 instances of cpoper at a time and would like each to know "which" it is so it can read from the correct named pipe.
I currently hack this by passing a name via a file to each, waiting for it to erase the file (as it's read the parameter), then the next and so on.  This way each cpoper instantiation can read from the correct pipe ... (these instances each work in parallel on data in 4 separate external drives...).

Anyhoo, what I'd prefer to do is pass the "which" info to each instantiation in the "open" CMD.

I've tried:          
       CMD := 'open /Users/alanbrowne/Pascal/cpoper --args A1';

but then the fpsystem call fails to run cpoper.  I've tried variations on that call (wrapping in ' and " and so on in many variations) but simply cannot get the parameter over to cpoper instances.

On the cpoper end I hope to simply do:       Vol := Paramstr(1);  //the passed parameter names the volume to be worked on.

Thx,
A
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Passing parameters to a program with fpSystem open
« Reply #1 on: October 14, 2019, 05:27:54 pm »
I am not entirely sure if Paramstr(x) will capture quotes strings or things such as that.

 I've had to at times read in the complete string and parse it myself.
The only true wisdom is knowing you know nothing

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Passing parameters to a program with fpSystem open
« Reply #2 on: October 14, 2019, 05:38:18 pm »
       CMD := 'open /Users/alanbrowne/Pascal/cpoper --args A1';
open: command
parameters for command open is:
/Users/alanbrowne/Pascal/cpoper: paramStr(1)
--args: paramstr(2)
A1: paramstr(3)

I think your programm (cpoper) gets no parameter, because itself is parameter for the command open.

Try with tprocess, tprocess is better.
https://wiki.lazarus.freepascal.org/Executing_External_Programs

or try:
 CMD := '/Users/alanbrowne/Pascal/cpoper --args A1';

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Passing parameters to a program with fpSystem open
« Reply #3 on: October 14, 2019, 06:56:43 pm »
@soner: per man open, args defines the parameters passed to the program that is opened.  So the first argument after --args is the first parameter to the program being opened.  IAC I passed 5 parameters after --args as an experiment - none got through.  Perhaps args is designed for specifics of C.[1]

The TProcess method is certainly better, but longer to implement than what I have now which is more than sufficient, if elegance challenged.

[1] man open </s>
     --args
         All remaining arguments are passed to the opened application in the argv parameter to main().
         These arguments are not opened or interpreted by the open tool.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Passing parameters to a program with fpSystem open
« Reply #4 on: October 14, 2019, 06:59:47 pm »
do not use fpsystem, but simply Tprocess
Specialize a type, not a var.

 

TinyPortal © 2005-2018