CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Restart/reload an impress from Perl

 



dwaynepeeters
New User

Apr 8, 2014, 2:38 AM

Post #1 of 2 (5535 views)
Restart/reload an impress from Perl Can't Post

Hi all,

I’m currently working on a project in which I would like to be able to restart an impress presentation from a perl script.
The script works just fine, it kills the presentation and restarts it, but the problem is that the script freezes after restarting the presentation. It never prints “Script end!”.
I know this is both a impress and mostly a perl related question but I was still wondering if someone could help me out?
Maybe there is a much simpler way (command) to restart an impress presentation?

My script looks like this:

if ($filesize != $filesize2)
{system(“cp -f /home/picuntu/Temporary/Presentatie.odp /home/picuntu/Desktop/Presentation.odp”);
system(“pkill -9 -f Presentation.odp”);
system(“libreoffice —quickstart -show —norestore /home/picuntu/Desktop/Presentation.odp”);
print “/n” . “Script end!” . “/n”;
break;

Any help would be much appreciated,

Kind regards,

Dwayne


FishMonger
Veteran / Moderator

Apr 8, 2014, 6:23 AM

Post #2 of 2 (5526 views)
Re: [dwaynepeeters] Restart/reload an impress from Perl [In reply to] Can't Post

Why are you using 'cp' and 'pkill' system calls? Are you not aware that perl has the built-in kill function to kill a process and the File::Copy module to copy files?

The script is not "freezing". The system function forks a new (child) process to run the command and waits for that process to complete/exit before proceeding to the next statement.

If you want it to return immediately, you'll need to run libreoffice as a background process.

Code
system("libreoffice —quickstart -show —norestore /home/picuntu/Desktop/Presentation.odp &");


A better method to do that would be to use the Proc::Background module.

Code
use Proc::Background; 

my $cmd = "libreoffice —quickstart -show —norestore /home/picuntu/Desktop/Presentation.odp";
my $libreoffice = Proc::Background->new($cmd);


http://perldoc.perl.org/functions/kill.html
http://perldoc.perl.org/functions/unlink.html
http://search.cpan.org/~rjbs/perl-5.18.2/lib/File/Copy.pm
http://search.cpan.org/~bzajac/Proc-Background-1.10/lib/Proc/Background.pm


(This post was edited by FishMonger on Apr 8, 2014, 6:24 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives