How can i execute "cal" of UNIX in xxx.pl ?

Discussion in 'Perl Misc' started by silvester, Nov 3, 2003.

  1. silvester

    silvester Guest

    Here is my code. ↓ (of course i have another relative xxx.html)

    #!/usr/local/bin/perl
    do "cgi-lib.pl"||die "error\n";
    &ReadParse;
    exec "cal $in{month} $in{year}";
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ↑Here is my question.
    i can't exec cal with month & year at the same time.
    for example,
    i can't exec "cal 11 2003";
    but it's ok to exec "cal 2003";

    what's wrong?
    or that's not supported by Perl?

    i need help, please.
     
    silvester, Nov 3, 2003
    #1
    1. Advertising

  2. silvester wrote:

    > Here is my code. ↓ (of course i have another relative xxx.html)
    >
    > #!/usr/local/bin/perl
    > do "cgi-lib.pl"||die "error\n";
    > &ReadParse;
    > exec "cal $in{month} $in{year}";
    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > ↑Here is my question.
    > i can't exec cal with month & year at the same time.
    > for example,
    > i can't exec "cal 11 2003";
    > but it's ok to exec "cal 2003";
    >
    > what's wrong?
    > or that's not supported by Perl?
    >
    > i need help, please.


    $ perl -e '$in{m}=11;$in{y}=2003;exec "cal $in{m} $in{y}";'
    November 2003
    Su Mo Tu We Th Fr Sa
    1
    2 3 4 5 6 7 8
    9 10 11 12 13 14 15
    16 17 18 19 20 21 22
    23 24 25 26 27 28 29
    30

    Works fine for me ... you may want to upgrade to a newer style of perl,
    e.g., one that doesn't use cgi-lib.pl ;-)

    Also, run your script through a debugger:

    $ perl -d xxx.pl

    Check what %in contains after ReadParse.

    Finally, if this is a CGI script, cal may or may not be in your PATH at that
    point. Try running with a full pathname, e.g. exec "/usr/bin/cal ..." (if
    that's where cal is on your system).
     
    Darin McBride, Nov 3, 2003
    #2
    1. Advertising

  3. silvester

    Ben Morrow Guest

    (silvester) wrote:
    > Here is my code. ↓ (of course i have another relative

    ^^^^^^^
    What is this?

    > xxx.html)




    >
    > #!/usr/local/bin/perl
    > do "cgi-lib.pl"||die "error\n";
    > &ReadParse;


    AAARGH! nononononono this is Perl4.

    Read
    perldoc -f use
    perldoc perlmod
    perldoc CGI

    > exec "cal $in{month} $in{year}";
    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > ↑Here is my question.
    > i can't exec cal with month & year at the same time.
    > for example,
    > i can't exec "cal 11 2003";
    > but it's ok to exec "cal 2003";


    What do you mean by 'i can't' and 'but it's ok'? What happens? What
    error messages do you get, or what output do you get that you didn't
    want?

    Also, you haven't printed an HTTP header yet.

    Ben

    --
    For the last month, a large number of PSNs in the Arpa[Inter-]net have been
    reporting symptoms of congestion ... These reports have been accompanied by an
    increasing number of user complaints ... As of June,... the Arpanet contained
    47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
     
    Ben Morrow, Nov 3, 2003
    #3
  4. On 3 Nov 2003 09:39:46 -0800
    (silvester) wrote:
    > Here is my code. ↓ (of course i have another relative
    > xxx.html)
    >
    > #!/usr/local/bin/perl


    Put a '-w' at the end of that first line to enable warnings.

    > do "cgi-lib.pl"||die "error\n";


    This is a Perl 4 (meaning, the _latest_ version of Perl is 5.8.1)
    library. Use the CGI module instead.

    > &ReadParse;


    Ditto :)

    > exec "cal $in{month} $in{year}";


    You _want_ the results of 'cat', don't you? Then use 'system', not
    'exec'.

    And .... Perl has _several_ modules to perform the same functions (and
    then some) as 'cal'.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    Playing an unamplified electric guitar is like strumming on a
    <picnic table. -- Dave Barry, "The Snake"
     
    James Willmore, Nov 3, 2003
    #4
  5. On Mon, 3 Nov 2003, Ben Morrow wrote:

    > (silvester) wrote:
    > > Here is my code. ↓ (of course i have another relative

    > ^^^^^^^
    > What is this?


    An un-called-for HTML-ised character reference to a downwards arrow,
    I'd say.

    Since the original posting's header said:

    Content-Type: text/plain; charset=ISO-8859-1

    it had no business using unsolicited "numerical character references".
    Guess whose software I'd tend to blame? (By the time the posting's
    gone through the Googroups gateway that the hon Usenaut was using in
    place of a real nntp server, there may little sign of the identity of
    the original "client" software that was used to access Googloups, but
    I have my suspicions...)

    > AAARGH! nononononono this is Perl4.


    "run away!" ;-))
     
    Alan J. Flavell, Nov 3, 2003
    #5
  6. James Willmore <> wrote:
    > On 3 Nov 2003 09:39:46 -0800
    > (silvester) wrote:



    >> do "cgi-lib.pl"||die "error\n";

    >
    > This is a Perl 4 (meaning, the _latest_ version of Perl is 5.8.1)



    Also meaning:

    It is 9 year old code.

    It is contemporary with Windows 3.1 (are you still using that too?).


    But the most pragmatic reason for switching to CGI.pm is:

    Nobody will help you when you have problems.

    It is hard to get worked up about stuff that old...


    >> exec "cal $in{month} $in{year}";

    >
    > You _want_ the results of 'cat', don't you? Then use 'system', not
    > 'exec'.



    Huh?

    That is either the wrong question or the wrong answer...

    You _want_ the results of 'cat', don't you? Then use backticks, not exec.

    You _want_ to have some more Perl program after launching "cal",
    don't you? Then use 'system', not 'exec'.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 4, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Åukasz Ligowski

    "xxx.has_key(a)" vs "a in xxx"

    Åukasz Ligowski, Oct 30, 2008, in forum: Python
    Replies:
    0
    Views:
    295
    Åukasz Ligowski
    Oct 30, 2008
  2. Replies:
    0
    Views:
    1,026
  3. Bert Leu

    value of type "xxx" cannot be converted to "xxx"

    Bert Leu, Jun 5, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    293
    Jesse Houwing
    Jun 6, 2007
  4. Richard Lionheart
    Replies:
    4
    Views:
    288
    Richard Lionheart
    May 5, 2004
  5. Iñaki Baz Castillo
    Replies:
    5
    Views:
    153
    Iñaki Baz Castillo
    Mar 30, 2008
Loading...

Share This Page