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

Silly me. What am I doing wrong? The following line: system ("c:\\Program Files\\Microsoft Office\\Office\\Excel.exe /p \"Book1.xls\""); returns the error: 'c:\Program' is not recognized as an internal or external command.... What don't I know about specifying the path correctly? Thanks. --Cypress

Replies are listed 'Best First'.
Re: printing MSExcel file?
by roboticus (Chancellor) on Dec 01, 2007 at 03:34 UTC
    You need to quote the string again. The shell that reads the command breaks it up on spaces unless properly quoted.

    Try an extra set of quotes for DOS/Win or backslashes for *Nix.

    ...roboticus

    Update: Try executing that exact command line in a standard DOS shell and see what happens... ;^)

    This would work in DOS/Win:

    C:\> "C:\Program Files\yadda yadda\foo.exe" argWithNoSpace "Arg with a + space"
    For *Nix it depends on your shell. I use bash:

    $ /DOS/C/Program\ Files/yadda\ yadda/foo.exe argWithNoSpaces Arg\ with +\ a\ space
Re: printing MSExcel file?
by memnoch (Scribe) on Dec 01, 2007 at 12:42 UTC
    Hi Cypress, Try this:

    system ("\"c:\\Program Files\\Microsoft Office\\Office\\Excel.exe\" /p Book1.xls");

    it works for me! You have to isolate the path to the executable from the rest of the command.

    Best wishes,
    memnoch

    Gloria in Excelsis Deo!
Re: printing MSExcel file?
by jrsimmon (Hermit) on Dec 01, 2007 at 14:05 UTC
    You can always just use the dos names for your path...
    system ("c:\\Progra~1\\Micros~1\\Office\\Excel.exe /p \"Book1.xls\"");
Re: printing MSExcel file?
by bdimych (Monk) on Dec 01, 2007 at 23:32 UTC
    I have not excel installed, but I can test it with IE. Multiargument "system" call works for me without any problems
    system("c:/program files/internet explorer/iexplore.exe", "-k", "googl +e.com");
Re: printing MSExcel file?
by cypress (Beadle) on Dec 02, 2007 at 09:09 UTC
    Thanks, all, but I'm still having no luck: the default printer (powered up) just sits there staring back at me, though I don't receive any Perl errors any longer. Could it be that the printer isn't selected correctly? I'm trying all sorts of variations of: $printer = "c:\\Progra~1\\Micros~1\\Office\\Excel.exe \/p"; $file = "Book1.xls"; system ($printer $file) or die "cannot"; On a side issue, how do I get a d@%! newline into my posts here? Thanks again, cypress
      cypress:

      Have you run it from the command line exactly as you're trying to call it from perl?

      Is it putting anything in the print queue? I had an app once that I worked on and nothing printed ... until someone put the proper paper size in. I had the wrong paper size for it, and they just kept piling up.

      Oh .. and for the last question, just use a <p> to insert line breaks.

      and use a <c> to start your code statements so it doesn't reformat it for you
      and then a </c> to end the code section.

      ...roboticus

Re: printing MSExcel file?
by cypress (Beadle) on Dec 05, 2007 at 02:31 UTC
    Thanks again, roboticus (and all).

    Let me try your last suggestion first and see whether I can get newlines into my posts.

    cypress

Re: printing MSExcel file?
by cypress (Beadle) on Dec 05, 2007 at 02:33 UTC
    Good. Now let me try your real suggestion. I'll post again tomorrow. cypress