in reply to Re: Portability question: Is there something like '#ifdef' in Perl?
in thread Portability question: Is there something like '#ifdef' in Perl?

I am using system and I cannot use exec, as I wait on the result (may be fork). But, I have'nt tried anything besides system. And the problem of 'spaces in the path' is certainly a hindrance in the 'system' call, so I had use the getshortname call :(

Could you please send me the variant or the reference to the document for the call that handles the space problem in system call?

Thanks, -sureshr
  • Comment on Re: Re: Portability question: Is there something like '#ifdef' in Perl?

Replies are listed 'Best First'.
Re: Re: Re: Portability question: Is there something like '#ifdef' in Perl?
by BrowserUk (Patriarch) on Sep 29, 2003 at 17:24 UTC

    If you use the scalar args form of system

    ... system( "command \\path\\with spaces\\file" ); ...

    you'll may have problems with the spaces.

    If you use the list form of the system function.

    ... system( '\path\to\command.exe', '\path\with spaces\file' ); ...

    Note the use of 's rather than "s, to avoid the need to escape the backslashes.

    cmd.exe will be bypassed and the spaces in the filename won't cause a problem. However, you will need to specify the full path of the command as well.

    You can also avoid the need for using short filenames by quoting the filepath.

    ... system( q[command "\path\with spaces\file" ] ); ...

    Which allows the shell to resolve the location of the command for you and forces it to see the quoted path as a single argument.

    Note though, if your in an open environment, the risk entailed in allowing your shell to do this for you.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      1) Use of single quotes: This is not possible, as I am generating the path at runtime based on some env vars and I think use of single-quotes would not expand the variables inside it.

      2) I am not quite comfortable using 'command', because its like relying too much on a system file's existence (for example, lets say, MS decides to change the command.com's name, though very rare it maybe. I am very reluctant to use of such tied code, unless there is some pressing need). A function like 'system' is rather more guaranteed to not change over time or gets itself (functionality) modified in versions to come, if need be.

      Anyhow, thanks for the pointers!

      -sureshr

        You misunderstand. My use of the word "command" was simply as a placeholder for whatever command you are using system to invoke, ... NOT a reference to the old 16-bit windows shell, "command.com". Ie.

        system( "command \\path\\with spaces\\file" );

        could be

        system( "notepad \\path\\with spaces\\file" );

        or

        system( "xcopy \\path\\with spaces\\file" );

        The same applies to all other uses of the text 'command' in the original post.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.