Marcus Lim
Marcus Lim

Reputation: 577

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.

Upvotes: 5

Views: 5505

Answers (2)

so not liopa
so not liopa

Reputation: 475

WWW::Mechanize::Firefox will launch firefox for you but you can use

system 1, qq{$ENV{PROGRAMFILES}\\Mozilla Firefox\\firefox.exe}

Upvotes: 0

simbabque
simbabque

Reputation: 54323

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.

Upvotes: 7

Related Questions