December 07, 2013 Re: regading detection of stdin | ||||
---|---|---|---|---|
| ||||
On Fri, 06 Dec 2013 06:42:01 +0100, Jesse Phillips" wrote:
>
> On Friday, 6 December 2013 at 02:41:28 UTC, Hugo Florentino wrote:
>>
>> I see... so the "problem" simply was that function readln was
>> expecting user input. In that case, this is not what I intended. I
>> want the application to receive the stdout of another command as
>> stdin, and to detect if nothing is sent. How coud I accomplish this?
>
> Then you'll want std.process[1]. This provides functions for
> "piping" output[2]. As for detecting output, that can only be
> verified once the other process has finished; to handle that it
> should be reasonable to execute[3] and check the complete output.
>
> 1. http://dlang.org/phobos/std_process.html
> 2. http://dlang.org/phobos/std_process.html#.pipeProcess
> 3. http://dlang.org/phobos/std_process.html#.execute
Hmm... I am not too clear even after reading the documentation. From
what I could understand, these are all wrappers around spawnProcess and
spawnShell, which are intended to launch a child process from the
application, but that is not quite what I need.
I simply want to support this kind of use:
echo -n "This is just a test" | myapplication
The command echo here serves only as an example, it could be any other
command not necessarily open-source or programmed in D.
What can I do?
Regards, Hugo
|
December 07, 2013 Re: regading detection of stdin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hugo Florentino | Sounds like what you need is to see if stdin is a tty. import core.sys.posix.unistd; // has isatty() void main() { import std.stdio; writeln(isatty(0)); // 0 is stdin, so this will show 1 if keyboard or 0 if pope } |
Copyright © 1999-2021 by the D Language Foundation