in reply to Re: Launch an exe using system
in thread Launch an exe using system

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.

Replies are listed 'Best First'.
Re^3: Launch an exe using system
by GrandFather (Saint) on Nov 14, 2011 at 08:54 UTC

    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
Re^3: Launch an exe using system
by Corion (Patriarch) on Nov 14, 2011 at 08:57 UTC

    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 ) ...

      Thanks of the response. I tried the following code :

      my $LifeCamLoc = "C:\\Program Files (x86)\\Microsoft LifeCam"; system('start "$LifeCamLoc"'); system('start LifeCam.exe');

        Maybe you want to read the documentation for the start command of cmd.exe?

        The start command takes at least two parameters, the title and the command to launch. So you will need to pass it two parameters from your script too.

        To get a feel for what the OS is going to see replace system with print then figure out if what you see is what you would type at the command line to get the effect you expect.

        True laziness is hard work
Re^3: Launch an exe using system
by davido (Cardinal) on Nov 14, 2011 at 08:52 UTC

    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

      It's not so much the Windows utilities that can't handle the spaces (although that may be true), but the command line parsing that is performed by Window's equivalent of the "shell". The quoting is needed to have a command line argument that includes spaces be treated as a single argument rather than being broken into multiple arguments at the spaces. Exactly the same situation exists for *nix shells, although the quoting options are different. Oh, and various *nixen have their share of utilities that don't play well with paths containing spaces too. ;)

      True laziness is hard work