Hello, The programming language “OCaml” supports also to start a background process by the function “Unix.system”. How can the corresponding process identification be determined? I would appreciate your advices. Regards, Markus
[-- Attachment #1: Type: text/plain, Size: 521 bytes --] You may be looking for the Unix.create_process function: https://ocaml.org/releases/4.11/htmlman/libref/Unix.html#1_Highlevelprocessandredirectionmanagement On Wed, Jan 6, 2021 at 3:05 PM Markus Elfring <Markus.Elfring@web.de> wrote: > Hello, > > The programming language “OCaml” supports also to start a background > process > by the function “Unix.system”. > How can the corresponding process identification be determined? > > I would appreciate your advices. > > Regards, > Markus > [-- Attachment #2: Type: text/html, Size: 984 bytes --]
> You may be looking for the > > Unix.create_process This function needs more input parameters than “Unix.system”. https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process Now I am curious which datum should be passed for the argument “stdin” if a program should be executed as a child process without extra standard input? Regards, Markus
[-- Attachment #1: Type: text/plain, Size: 819 bytes --] My understanding is that if "prog" is the name of the program to run, then Unix.system (Filename.quote_command prog args) is equivalent to Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout ~stderr:Unix.stderr or (shorter) Unix.(create_process prog args ~stdin ~stdour ~stderr) On Sat, Jan 9, 2021 at 5:08 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > You may be looking for the > > > > Unix.create_process > > This function needs more input parameters than “Unix.system”. > > https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process > > Now I am curious which datum should be passed for the argument “stdin” > if a program should be executed as a child process without extra standard > input? > > Regards, > Markus > [-- Attachment #2: Type: text/html, Size: 1401 bytes --]
> My understanding is that if "prog" is the name of the program to run, then
>
> Unix.system (Filename.quote_command prog args)
>
> is equivalent to
>
> Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout ~stderr:Unix.stderr
Thanks for another feedback.
But I wonder how it fits to the programming concern for the omission of a standard input selection
(because an input file would be specified within the data for the parameter “args”).
Regards,
Markus
[-- Attachment #1: Type: text/plain, Size: 1189 bytes --] On Sat, Jan 9, 2021 at 5:34 PM Gabriel Scherer <gabriel.scherer@gmail.com> wrote: > My understanding is that if "prog" is the name of the program to run, then > > Unix.system (Filename.quote_command prog args) > > is equivalent to > > Unix.create_process prog args ~stdin:Unix.stdin ~stdout:Unix.stdout > ~stderr:Unix.stderr > Not quite: args should be Array.of_list (prog :: args). Argument number 0 is, by Unix convention, the name of the program. The original poster may be looking for the Unix.open_process family of functions. - Xavier Leroy > or (shorter) > > Unix.(create_process prog args ~stdin ~stdour ~stderr) > > On Sat, Jan 9, 2021 at 5:08 PM Markus Elfring <Markus.Elfring@web.de> > wrote: > >> > You may be looking for the >> > >> > Unix.create_process >> >> This function needs more input parameters than “Unix.system”. >> >> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process >> >> Now I am curious which datum should be passed for the argument “stdin” >> if a program should be executed as a child process without extra standard >> input? >> >> Regards, >> Markus >> > [-- Attachment #2: Type: text/html, Size: 2414 bytes --]
> The original poster may be looking for the Unix.open_process family of functions.
This looks unlikely when these function variants do not return an identification
for the started child process.
Regards,
Markus
> Am 09.01.2021 um 17:08 schrieb Markus Elfring <Markus.Elfring@web.de>:
>
>
>>
>> You may be looking for the
>>
>> Unix.create_process
>
> This function needs more input parameters than “Unix.system”.
> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process
>
> Now I am curious which datum should be passed for the argument “stdin”
> if a program should be executed as a child process without extra standard input?
[...]
It would be much easier to point you to the right functions, if you would give some more details on what you want to do, e.g. an example command that you want to use, and to tell us, if you want to pass data into it or read data from it, and so on.
The less information you provide, the fuzzier / general the anwers.
It might also interest you, that there is a seperated manual on how to do unix-programming with OCaml.
Ciao,
Oliver
> Am 09.01.2021 um 17:52 schrieb Markus Elfring <Markus.Elfring@web.de>:
>
>
>>
>> The original poster may be looking for the Unix.open_process family of functions.
>
> This looks unlikely when these function variants do not return an identification
> for the started child process.
Do you mean the process ID, when talking about "an identification"?
Do you really need it?
You may want to look for fork, exec and pipe....
Ciao,
Oliver
>> https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALcreate_process >> >> Now I am curious which datum should be passed for the argument “stdin” >> if a program should be executed as a child process without extra standard input? > [...] > > It would be much easier to point you to the right functions, Thanks for your growing development interest. > if you would give some more details on what you want to do, I became interested in the safe handling of commands for PostScript viewers. > e.g. an example command that you want to use, and to tell us, if you want to pass data into it or read data from it, and so on. Would you like to add any comments to background information which was provided for code review with the commit “add error checking” (from 2020-12-24) for an evolving software? https://github.com/coccinelle/coccinelle/commit/4127b5546ccd929ae017565e710a3c9092f0bb0c Regards, Markus
> Do you mean the process ID, when talking about "an identification"? Yes. > Do you really need it? I imagine that a PID will be needed so that a corresponding wait function call can be performed finally. https://ocaml.org/releases/4.11/htmlman/libref/UnixLabels.html#VALwaitpid Regards, Markus
> The less information you provide, the fuzzier / general the anwers.
>
> It might also interest you, that there is a seperated manual on how to do unix-programming with OCaml.
I stumbled on general function properties for this programming interface.
* Which process should open an input file for a child process?
* Which functions do return an identification (a PID) for the started child process accordingly?
Regards,
Markus