gsaro has asked for the wisdom of the Perl Monks concerning the following question:

My C program needs command line arguments. the following line is printing what I need.

 perl -e 'print "characters"."numbers\n";'

if test.c and test is the output file is my prog What is the method to direct output of perl command to my c prog?

Replies are listed 'Best First'.
Re: passing arguments to c prog
by aitap (Curate) on Aug 24, 2013 at 10:14 UTC

    You can run commands from perl using system and backticks. If that's not what you want, what command line shell do you use? (And that's not a Perl question this way.) For example, passing STDOUT of Perl program as an argument to another program looks like this in a POSIX shell: ./c-program "$(perl -e "whatever")".

    Edit: corrected a typo.
      Thank you for your reply. I am using bash shell and "$(perl -e 'print "\x44\x84\xaa\xbb";')" works for me. I do not know perl. Passing numbers to c(executable) as command line args was not working as they are treated as characters. A lot of manipulation was needed to achieve what I needed. I know that python has the required commands. just wondered about perl.
Re: passing arguments to c prog
by Laurent_R (Canon) on Aug 24, 2013 at 14:30 UTC

    Since your Perl one-liner seems to indicate that you work on some flavor of Unix, you could simply redirect the output toward your C program:

    perl -e 'print "AAAA"."BBBB"."\x44\x84\n";' > test.c

    Or, if you just want to append the output to an existing C program file:

    perl -e 'print "AAAA"."BBBB"."\x44\x84\n";' >> test.c

    Update: from your new message on Aug 24, 2013 at 17:53 UTC, it looks like I completely misunderstood your requirement. Sorry about that and forget the above.