in reply to Re: How to use system command in perl script?
in thread How to use system command in perl script?
#!/usr/bin/perl use strict; use CGI; print "Content-type: text/plain\n\n"; my $q=new CGI; my $codes=$q->param('c_code'); my $file = "code.cpp"; open(FH, ">$file"); ### Must chmod Before writing, system("chmod 0777 code.cpp"); ### Can't create and change mode??? +? print FH "$codes"; close(FH); &run; exit(0); sub run { system("gcc code.cpp"); system("a.out/>result.txt"); open(F,"result.txt"); while(<F>) { print $_,"\n"; } close(F); }
Edited by Chady -- added code tags.
|
|---|