Suppose I have a perl program such as:
my $c = "MyDataToCProg";
open my $h, '-|', 'myCProg', "$c";
my @result = <$h>;
close $h;
print "Result: " . $result[0] . "\n";
Now, myCProg is a program compiled with gcc. The C program's output would be a printf statement which would end up in the perl program's $result[0] variable.
Is there a better way to extract output out of a C program than through printing with printf? For example, anyone could also run 'myCProg' from the command line and also see output. I want the output to only be seen in the perl program an NOT viewable if someone ran the program at the command line.
Anyone know how to do this?
Sorry, I don't have a C Program handy, but anything that has a printf statement (even a simple Hello World) and takes an argument (maybe prints "Hello [yourname]" would work for this example.
Copyright Notice:Content Author:「user5074403」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32105815/how-do-i-securely-get-data-transferred-from-c-to-perl