Thread frage zu verwendung des "system" befehls (5 answers)
Opened by lordy2008 at 2008-11-10 17:09

topeg
 2008-11-10 18:21
#116169 #116169
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
lordy2008+2008-11-10 16:09:04--
Code (perl): (dl )
1
2
$cmd = "g_rms -f " . $f1 ." -s " . $f2 . " << Ende\n 1 << 1 << Ende";
system $cmd;

Das sieht für mich recht merkwürdig aus. Ich glaube nicht, dass das korrekt ausgeführt wird.
Ich habe mal Testweise das gemacht:
Code (perl): (dl )
system("cat <<ENDE - \n1 << 1 << ENDE")

und dabei kam raus:
Code: (dl )
1 << 1 << ENDE

Als ich aber schrieb:
Code (perl): (dl )
system("cat <<ENDE - \n1\n1\nENDE")

kam raus:
Code: (dl )
1
2
1
1

Was für eine Shell nutzt du (ich habe hier die bash)?
Also ich würde das so schreiben:
Code (perl): (dl )
1
2
$cmd = "g_rms -f $f1 -s $f2 << Ende\n1\n1\nEnde";
system $cmd ==0 or die "Fehler ($?)\n";


lordy2008+2008-11-10 16:09:04--
Code (perl): (dl )
1
2
$cmd = "make_ndx -f " . $f1 . " << Ende\n r ".$alpha1HelixStart. "-" .$alpha1HelixEnd. " << r " . $alpha2HelixStart . "-" . $alpha2HelixEnd." << q << Ende";
system $cmd;

Ich würde das so schreiben:
Code (perl): (dl )
1
2
3
4
5
6
$cmd = "make_ndx -f $f1 << Ende\n".
       "r ${alpha1HelixStart}-${alpha1HelixEnd}\n".
       "r ${alpha2HelixStart}-${alpha2HelixEnd}\n".
       "q\n".
       "Ende";
system $cmd ==0 or die "Fehler ($?)\n";



Alternativ könntest du auch so vorgehen:
Code (perl): (dl )
1
2
3
4
5
open(my $cmd, "| make_ndx -f $f1") or die "Fehler: $!";
print $cmd "r ${alpha1HelixStart}-${alpha1HelixEnd}\n";
print $cmd "r ${alpha2HelixStart}-${alpha2HelixEnd}\n";
print $cmd "q\n";
close($cmd) or die "Fehler: $!\n";

View full thread frage zu verwendung des "system" befehls