Hello,
I have a C program say cProg.c that asks the user to enter a filename, (opens that file and operates over it) and saves the output in a file "output.txt"
I have a PERL script main.pl
I wish to somehow generate the output.txt when I run main.pl
I am using vi editor to do all this and my university already has all the required compilers, interpreters etc...
For easier understanding, lets say this is how the C file looks like:
==============cProg.c=====================
#include< stdio.h>
main (int argc, char *argv[])
{
FILE *fp;
if (argc!= 2)
printf ("Please Enter a FileName\n");
else
{
fp = fopen (argv[1], "r");
printf ("File Found\n");
fclose (fp);
}
return 0;
}
=================cProg.c Ends=================
I compile and run this program this way:
[ ~ ] gcc cProg.c
[ ~ ] ./a.out input.txt > output.txt
This generates output.txt which has "File Found" as its only contents.
Now I wish to write a PERL script which would automatically generate "output.txt" when i execute the PERL script
=================main.pl====================
#!/usr/bin/perl
./a.out input.txt > output.txt ###How should I do this?
$output_file="output.txt";
open(OP, $output_file) || die("Could not open file!");
@sequence=<OP>; # tosses the contents of "output.txt" in an array
+"@sequence" to work on.
===============mail.pl ENDS====================
Kindly show me the path to heaven =)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.