Rank beginner here please be gentle…
I’m writing a program in perl that finds all of a certain file type and calls and another program called newstack to convert the file types.
When I run newstack oldfileame newfilename from my shell it works fine.
when my program runs system("newstack oldfileame newfilename") newstack returns the error:
ERROR: NEWSTACK - NO INPUT FILE SELECTED
sh: line1: ./oldfilename: cannot execute binary file
If I write a shell script that does the same thing, running newstack on the files one at a time it works fine. Is there something I’m missing here why it fails when run within the context of the perl program?
Newstack is from the IMOD suite of programs, I don’t know what it’s written in. The files are mrc files which are binary image files.
EDIT:: Here’s the actual code as requested:
print "Enter the rootname of the files to be converted: ";
my $filename = <STDIN>;
chop $filename;
my @files = qx(ls $filename*.mrc);
open LOGFILE, (">modeconvert-log");
foreach my $mrc (@files)
{
print LOGFILE "$mrc";
system("newstack -mode 2 $mrc $mrc");
}
my $fileno = @files;
print "$fileno files converted\n";
I added chop $mrc after line 8 and it fixed the problem
The code you posted and the code you executed differ. In the code you executed, there was a newline after
newstackRemove the newline using
chomp($x)or using$x =~ s/\s+\z//;.should be
Or better yet:
The above and other fixes: