Re: how to open a file with space in its name
by Corion (Patriarch) on Jan 05, 2006 at 08:21 UTC
|
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: $! / $?";
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] [select] |
|
|
it was working correctly thank you very much
| [reply] |
Re: how to open a file with space in its name
by inman (Curate) on Jan 05, 2006 at 09:38 UTC
|
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. | [reply] [d/l] |
|
|
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)
| [reply] [d/l] [select] |
|
|
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.
| [reply] [d/l] [select] |
|
|
|
|
In unix , how can we open a file with space in its name.
Please paste the command and help me out.
| [reply] |
|
|
Use the multiple argument version of system
| [reply] |
[OT] Re: how to open a file with space in its name
by astroboy (Chaplain) on Jan 05, 2006 at 14:23 UTC
|
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 | [reply] |
Re: how to open a file with space in its name
by samizdat (Vicar) on Jan 05, 2006 at 14:01 UTC
|
| [reply] |