priyaviswam has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I want to launch a exe in the C:/Program Files (x86). When I try to run this system("start C:\\Program Files (x86)\\Microsoft LifeCam\\LifeCam.exe"); It returned me an error. Please suggest.

Replies are listed 'Best First'.
Re: Launch an exe using system
by Anonymous Monk on Nov 14, 2011 at 07:35 UTC

      Thanks for your suggestion. The error is "Windows cannot find C:/program". The space in the program file is not read. So I was not able to launch the exe.

        Well, that is an error message from the shell you're using, the shell which has the start command

        You can read about it if you use the help command ( help start)

        You can learn more about shells if you read Behind the GUI lives the Shell and perlrun

        If you use Proc::Background, you don't have to concern yourself with the shell start command

      The error is "Windows cannot find C:/program. Make sure you type the name correctly, and then try again". The space in the program file is not read. So I was not able to launch the exe.

        Well, there is the clue right there: the path to the "program" you want got truncated at the space. Just as you do on the command line you need to quote parameters that include spaces and similar interesting characters. One way to do that is:

        system(qq{start "C:\\Program Files (x86)\\Microsoft LifeCam\\LifeCam.e +xe"});

        See Quote and Quote like Operators

        True laziness is hard work

        You will need to supply proper quotes to the start command:

        my $cmd = qq{start "C:\\Program Files (x86)\\Microsoft LifeCam\\LifeCa +m.exe"}; system($cmd) == 0 or die "Couldn't launch [$cmd]: $! / $?";

        Alternatively, you can use the form of system(1, ...) as documented in perlport:

        system( 1, $cmd ) ...

        How would you handle that if you were typing start ..... on the command line? There are some Windows utilities that don't play nice with spaces in the path names, and for those you usually have to use quoting.

        That being the case, you're not looking at a Perl problem, you're looking at a "I don't know how to use my operating system." problem. That's alright. But you should at least be aware where the issue is.

        Try this (untested, but ...at least try it... ;)

        system( qq/start "C:\\Program Files (x86)\\Microsoft LifeCam\\LifeCam.exe"/ );

        Dave

Re: Launch an exe using system
by ansh batra (Friar) on Nov 14, 2011 at 08:19 UTC
    It returned me an error
    what error?
    is it some secret???