Control a non-perl image viewer from perl script

From: Harry Putnam (reader_at_newsguy.com)
Date: 10/30/03


To: beginners@perl.org
Date: Thu, 30 Oct 2003 09:27:49 -0600

Below is a (non-finished) script that trys to run a linux viewer
called eog (eye of gnome) in a script that will eventually allow me to
power thru long lists of image files and rename them as I go.

The idea was a cmdline tool that would pop up a view of each image
then query user for new name. Kill that process and move on to next
item in list.

I couldn't think of any better way than to query `ps' for the pid and
run `kill' on it. However even that isn't working.

But I wondered if there is a better way of doing this that is still
fairly basic?

#!/usr/local/bin/perl -w
$question = "New name please => ";
$ext=shift;
$ls_proc = "ls *.$ext";
open(LS_PROC," $ls_proc|");
while(<LS_PROC>){
   chomp;
   push @ls_array,$_;
}
for(@ls_array){
   $pic = $_;
   system("eog $pic &");
   print $question;
   chomp ($newname = <STDIN>);
   print "<$newname>\n";
   qx(cp -a $pic "$newname.$ext");
## rename $_ "$newname.$ext";
   open(PS_PROC,"ps wwaux|");
   while(<PS_PROC>){
     chomp;
     if($_ =~ /^$ENV{LOGNAME}.*eog.*\.jpg$/){
        my $line = $_;
        print "hpdb \$line = $line\n";
        <STDIN>;
        $pid = (split(/\s+/,$line))[1];
        print "hpdb \$pid = $pid\n";
        <STDIN>;
        print "kill -15 on $pid?\n";
        $ans = <STDIN>;
        if ($ans eq "y"){
           print "Killing -15 on pid <$pid>\n";
           qx(kill -15 $pid);
        }
     }
   }
   close(PS_PROC);
}
close(LS_PROC);



Relevant Pages

  • Re: How to kill a logged in user?
    ... > in your script. ... >> Anyone know what packages are on the rescue CD? ... How to kill a logged in user? ... Also on my TODO list is a mailing list export/import modul, from which we can convert mail threads into FAQs. ...
    (Fedora)
  • RE: How to kill a logged in user?
    ... How to kill a logged in user? ... information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, ... > in your script. ... from which we can convert mail threads into FAQs. ...
    (Fedora)
  • Re: Script to Rename Computer Name in Domain
    ... i looking a script to rename computer name in domain server 2003 ... To rename a computer you bind to the parent OU/Container of the computer ... you would need to also prompt for the current name. ... ' Bind to the parent OU/container of computer object. ...
    (microsoft.public.windows.server.scripting)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • Re: rename a local group in windows 2003
    ... strComputer = objShell.ExpandEnvironmentStrings ... I tried to rename several local groups using the MoveHere method ... Didn't matter if I ran the script on the ... WinNT provider only rename domain groups, ...
    (microsoft.public.windows.server.scripting)