Jump to content
Vhaerun

Cum sa rulezi cod C in linia de comanda

Recommended Posts

Posted

Programand la o chestie in C , ma gandeam "ce fain ar fi daca as avea ceva gen perl -e" , si am zis "hai sa fac" :)

Asta a iesit :


# C command-line interpreter

use strict;

my $command = shift || die "comanda c\n";
my $path_to_compiler = "\"C:\\Program Files\\Wascana\\mingw\\bin\\gcc.exe\"";
my $output_file = "test.exe";
my $compiler_options = " -o $output_file -g";

open(F,">temp.c") || die "nu pot creea fisier temporar\n";

print F "#include <stdio.h>\n";
print F "int main(int argc,char* argv[]) {\n";
print F "$command\n";
print F "return 0;\n}\n";

close F || die "nu pot inchide fisierul $!\n";

my $b_output = `$path_to_compiler temp.c $compiler_options`;

if($b_output =~ /error/i) {
print "EROARE: $b_output\n";
}

my $output = ($^O ne "MSWin32") ? `./$output_file` : `$output_file`;

print $output,"\n";

sub END {

if(-e "temp.c") {
unlink("temp.c");
}
if(-e $output_file) {
unlink($output_file);
}

}

Scriptul poate fi rulat astfel :

perl script.pl "printf(\"salut\");"

perl script.pl "int i=0;while(i<10) { printf(\"%d\",i);i++; }"

Optiunile mele sunt pt. IDE-ul Wascana , teoretic ar trebui sa poti configura orice compilator . Teoretic .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...