[fpc-pascal] It is possible to pass command line to pascal
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Sun Jun 30 14:14:56 CEST 2013
Rainer Stratmann wrote:
> On Sunday 30 June 2013 12:32:30 you wrote:
>> Rainer Stratmann wrote:
>>> On Sunday 30 June 2013 00:59:59 you wrote:
>>>> I Tried, but only return an integer not a string value.
>>> Thats right.
>>>
>>> You have to put the result in a file and then afterwards read the file.
>>>
>>> ls uname -r > file.txt
>> I'm sorry, but that's misleading on at least two accounts. The first is
>> that redirection (> and so on) is a property of the shell, so it won't
>> work unless you pass the entire command to a shell with (typically) the
>> -c option. The second is that as linked by leledumbo earlier
>> http://wiki.lazarus.freepascal.org/Executing_External_Programs there are
>> specific facilities in the runtimes to do this sort of thing and they
>> don't, as a rule, involve temporary files.
>>
>> If I had to go on, what's that -r supposed to be doing?
>
> It is not too difficult to find out.
>
> If you speed up your engine then you can find out that he wants to know the
> actual Linux kernel number.
>
> 'uname -r'
In which case why is he putting ls in front of it? -r is a valid option
to both uname and ls, so since we're already looking at a broken command
it's entirely valid to ask which it's supposed to apply to.
> With 'uname -r > file.txt' you redirect the output in a file.
> Then cou can read the file.
>
> I am sorry, but you try to make a very simple thing complicated.
You might call having to invoke a shell with the -c option to get the
redirection working, working out where to put the temporary file,
deleting it on completion and making sure that all error conditions are
handled "simple". I certainly don't.
But as Marco has already reminded us, the information is already
available from a standard library call. Calling an external program is
not something to be approached for a trivial reason, unless you're
writing shell or in a scripting language such as Perl where it might be
less trouble than searching CPAN for the appropriate extension module.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list