Jemand zu Hause?Leser: 28
system('MyOtherScript','Arg1','Arg2,'Arg3','>','outfile.xml');system('MyOtherScript Arg1 Arg2 Arg3 > outfile.xml');
system("your command here") == 0 or die "'your command here' failed: $!\n";
2010-09-23T09:44:14 LinuxerBei Verwendung von System solltest Du auch den Erfolg prüfen:
Code (perl): (dl )system("your command here") == 0 or die "'your command here' failed: $!\n";
1
2
3
$ perl -wle 'system("not", "here") == 0 or die "failed with $?: $!\n";'
Can't exec "not": No such file or directory at -e line 1.
failed with -1: No such file or directory1 2 3 4 5 6 7 8 9 10
if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; }
system('script','-m','test.list','-s', $outlistfile,'--nolabels','--viterbi','>','outfile.xml');2010-09-23T10:59:03 odiumAlso der original Aufruf sieht etwa so aus:
Code: (dl )system('script','-m','test.list','-s', $outlistfile,'--nolabels','--viterbi','>','outfile.xml');
system('script -m test.list -s '.$outlistfile.' --nolabels --viterbi >outfile.xml');
1 2 3 4 5 6 7 8 9 10 11 12 13 14
my $pid; select undef, undef, undef, 0.1 until defined($pid=fork); # stellt sicher, dass fork() auch klappt unless($pid) { close STDOUT; open STDOUT, '>', 'outfile.xml' or die; exec 'script','-m','test.list','-s', $outlistfile,'--nolabels','--viterbi'; # hier sollten wir nicht landen, es sei denn exec() geht schief. exit -1; # zur Sicherheit kann man hier auch mehr Varianten des Beendens implementieren, z.B: # kill KILL=>$$; # POSIX::_exit -1; } waitpid $pid; $rc=$?;
IPC::System::Simple oder
IO::CaptureOutput benutzt. Das erste Modul benutzt Pipes, das zweite benutzt temporaere Dateien.
IPC::Run benutzen. Das ist ein recht umfangreiches Modul mit einer etwas gewoehnungsbeduerftigen API, aber es kann bestimmt Dein Problem loesen.
IPC::System::Simple,
Path::Class2010-09-23T16:22:38 betterworldWarum moechtest Du die Ausgabe umleiten? Um die Datei danach gleich in Perl weiterzuverarbeiten? In dem Fall kann man die Ausgabe leicht abfangen, indem man eine Pipe oeffnet...
Tipp zum Debugging