how to open a file with space in its name
arunmep
created: 2006-01-05 03:18:08
hi everybody iam using a command "sub{system "start soffice $file"})" to open a external word file but the problem is the file name has a space in it so it cant open the file please suggest me a way to open it .
Re: how to open a file with space in its name
created: 2006-01-05 03:21:10

Use the list version of system, which is safer anyway:

my @cmd = ($ENV{COMSPEC}, "/c", "start", "soffice.exe", $file);
system(@cmd) == 0
  or die "Couldn't launch @cmd: $! / $?";
Re^2: how to open a file with space in its name
created: 2006-01-05 03:31:18
it was working correctly thank you very much
Re^2: how to open a file with space in its name
created: 2006-01-05 20:19:48
Until very recently, perl on Win32 allegedly simply turned the system LIST into the system STRING version, without adding quotes. In other words, it still wouldn't have worked.

I'm not sure when the backward incompatible change was introduced.

Re: how to open a file with space in its name
created: 2006-01-05 04:38:00
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.

Re^2: how to open a file with space in its name
created: 2006-01-05 10:35:35
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 [/index.pl?node_id=56739#Best|best] work - (1 2 3)

Re^3: how to open a file with space in its name
created: 2006-01-05 10:37:04

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.

Re^4: how to open a file with space in its name
created: 2006-01-05 11:44:55
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: how to open a file with space in its name
created: 2006-01-05 09:01:48
It also helps in making it universal to add './' (UN!X) or '.\' (M$W) to the front of the filename. Some web designers (including mine) use -filename.inc strings in order to make them difficult to read or list.

Don Wilde
"There's more than one level to any answer."
[OT] Re: how to open a file with space in its name
created: 2006-01-05 09:23:30
It looks like the OP may be performing this operation under Windows (space in the name). When specifically code for that OS, I usually pass the file name to Win32::GetShortPathName, which will provide the canonical short name (sans spaces, 8.3 format), and I dont have to worry about spaces in the names

perlmonks.org content © perlmonks.org and arunmep, astroboy, bart, Corion, dwildesnl, inman, suaveant

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03