Sunday, August 2, 2009

Can I open another program from perl??

When I use the function "open" (let's say) C:\program files\itunes\itunes Perl doesn't takes it as a syntax error, but doesn't open the program either. What am I doing wrong??

Can I open another program from perl??
The “open” command is used for opening a file for reading and writing, as opposed to executing it as you are attempting to do.





You should be able to achieve what you’re after with system() or exec(). system() will wait for itunes to finish before carrying on with your program, so I would imagine exec() is what you’re after:





exec('C:\Program Files\iTunes\iTunes.exe') or die "Could not exec iTunes.exe: $!";








Best wishes,


Dave Cardwell.


http://davecardwell.co.uk/perl/
Reply:What are you trying to do - open a file to read or execute a program?





itunes.exe is a program in the directory you mentioned.





So instead of opening it as a file to read, you need to execute it as a program like this:





system("C:\\program files\\itunes\\itunes.exe");





(You need to escape the backslashes in a string so that's why there are double slashes)


No comments:

Post a Comment