On Tuesday, January 22, 2013 7:11:52 AM UTC-8, ccc31807 wrote:
> I have a small C program that displays file attributes, essentially running the stat command and emitting the output to the console.
>
>
>
> This morning, I have a new requirement -- to nicely format the output, printing the field names in CAPS and justifying the field values.
>
>
>
> C isn't my game, and while I probably could (with some effort) read up onreading in system output as strings, munging them, and displaying them, ifit's possible I'd rather use Perl. The program must be self contained in one exe file. The object is to save a manager from knowing anything about the stat command (yeah, I know.)
>
>
>
> Is this doable? Or must I write the entire thing in C?
>
>
IIUC (and I'm not at all sure I do), you could
comment out the existing code in the .exe and
hack up a replacement to shell out to a runnable
perl script
Of course, just adding some formatting to the
original would probably be easier. But, if you
want the former and, assuming .exe takes a file
as its only argument, here's a quick sketch:
#include <stdio.h>
int main( int argc, char *argv[] ) {
// put entire perl script in string
char *perlsource = "#!/usr/bin/perl\n...";
// output perl source to file
FILE *fp;
char *perlfile = "/tmp/doppelgaenger.pl"; // edit
// add error checking to open/flose/system
fp = fopen(perlfile, "w");
fprintf(fp, "%s\n", perlsource);
fclose(fp);
char cmd[100];
sprintf(cmd, "perl %s %s", perlfile, argv[1] );
system(cmd);
}
--
Charles DeRykus
|