Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: how to open a file with space in its name

by inman (Curate)
on Jan 05, 2006 at 09:38 UTC ( [id://521152]=note: print w/replies, xml ) Need Help??


in reply to how to open a file with space in its name

I amd assuming that you are using Windows - A file path with embedded spaces needs to be delimited by double quotes. Add escaped double quotes around your $file. This is what you would have to do if you typed in the command yourself.

sub{system "start soffice \"$file\""})

As mentioned previously, the new style of system command removes this ambiguity and will make for a more portable program.

Replies are listed 'Best First'.
Re^2: how to open a file with space in its name
by suaveant (Parson) on Jan 05, 2006 at 15:35 UTC
    If one is trying to escape filenames etc in a situation like this I prefer
    "start soffice \Q$file\E";
    to
    "start soffice \"$file\"";
    that way anything weird in the string is escaped, including " chars that may be in it... of course, the list version of system is safer.

                    - Ant
                    - Some of my best work - (1 2 3)

      Which will not work for Win32 filenames, as a file named c\:\\autoexec\.bat does not exist.

      Also, the quoting rule of double quotes (") is different for cmd.exe too - "" gets converted to ", """ gets converted to "" and so on. I think. In any case, quotemeta is not what you want when quoting strings for cmd.exe or command.com.

        Too true... I have written Perl on Windows all of about twice, so I tend to be biased towards Unix-style programming, my bad.

                        - Ant
                        - Some of my best work - (1 2 3)

Re^2: how to open a file with space in its name
by Anonymous Monk on Nov 04, 2008 at 13:30 UTC
    In unix , how can we open a file with space in its name. Please paste the command and help me out.
      Use the multiple argument version of system

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found