Re: [Console_CommandLine] read '-' as an argument
| From: | Reuben Cummings | Date: | Sat, 24 Mar 2012 13:59:50 +0000 |
| Subject: | Re: [Console_CommandLine] read '-' as an argument | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-31473@lists.php.net to get a copy of this message | ||
As a follow-up, how do check whether the argument was read via stdin or not? I want to process the
data according to how it was entered (e.g. like how md5 can hash either text via a pipe, or a file).
On Nov 4, 2011, at 3:47 PM, Reuben Cummings wrote:
> Ok, my setup is a bit more complex but I'll try your code and then see
> if I can adapt it. Thanks!
>
> Reuben
>
> On Thu, Nov 3, 2011 at 10:59 AM, David Jean Louis <izimobil@gmail.com> wrote:
>> Hi,
>>
>> How do I set up the parser to read '-' as an argument? I want an
>> option to read from standard input and most other cli programs use
>> '-'. I want to be able to type the following:
>>
>> echo argument | myprogram -
>>
>> When I try this with Console_CommandLine, it just hangs so I have to
>> use another character instead (I use '$').
>>
>> Well, it works for me:
>>
>> test.php:
>>
>> <?php
>> require_once 'Console/CommandLine.php';
>> $parser = new Console_CommandLine();
>> $parser->addArgument('data');
>> try {
>> $result = $parser->parse();
>> print_r($result->args);
>> } catch (Exception $exc) {
>> $parser->displayError($exc->getMessage());
>> }
>> ?>
>>
>> $ echo foo |php test.php -
>> Array
>> (
>> [data] => foo
>>
>> )
>>
>>
>> --
>> David