Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a program from perl?

How do i launch firefox from perl? i just need to launch the browser so WWW::Mechanize::Firefox can manipulate it. Searching around stackoverflow ive seen a few solutionsl like system('start cmd.exe /k $cmd) where $cmd is arguments to throw as input once cmd is started.

However, these have not helped me to solve my problem at all.

solutions ive tried

system("start cmd.exe /k start firefox");
system("firefox");
system("cmd","start","firefox");
system("cmd start firefox");

Basically a lot of the alternatives ive found, but i could not launch Firefox browser at all.

like image 530
Marcus Lim Avatar asked Nov 09 '12 09:11

Marcus Lim


1 Answers

You're on the right track. Your second line is almost correct. If firefox is not in your PATH environment variable, you need to supply the complete path.

Click on the Firefox icon on your desktop, open the properties and check where the firefox executable is located. Then use that with your system call.

For me, it looks like this (the ' are for Perl's string, the " are for the Windows shell, because the path has spaces in it):

system('"C:\Programme\Mozilla Firefox\firefox.exe"');

You can test it by opening a new command line (win + r, cmd), cding to the directory where your Perl program is run from, and just entering the command:

C:\Dokumente und Einstellungen\simbabque>"C:\Programme\Mozilla Firefox\firefox.exe"

It will not print anything, but just open a new Firefox window after a couple of seconds. So you'd probably need to hold your program execution in Perl while the browser is starting up.

like image 176
simbabque Avatar answered Nov 09 '22 22:11

simbabque