I’m having a problem running a shell command where the path of the shell command is on a Chinese system using Chinese encoding.
I have a folderitem which points to ‘C:\Documents and Settings\Eric\??\folder’. Folderitem.exists is True.
dim fpath as string = folderitem.shellpath
On my (British English) system:
fpath is “C:\DOCUME~1\Eric\263E~1\folder”
When I run: Shell.execute("cd "+fpath). It succeeds - Shell.ErrorCode=0
So far, so good.
When I run it on a Chinese system, however fpath retains it’s Chinese path and now always fails when passed as a path to shell.execute
“C:\DOCUME~1\Eric\??\folder”
When I run Shell.execute("cd "+fpath). It fails - Shell.ErrorCode=1. I can’t read Shell.Result as I can’t work out what encoding the result comes back as.
If I run cd "C:\\DOCUME~1\\Eric\\??\\folder" from a command prompt(cmd.exe) it works.
So, I either have an environmental variable problem (why does it work from cmd.exe?) or a path encoding issue.
Anyone have an idea?
I tried the ‘Interactive Shell’ example on the system and all the paths are a mess. Just typing dir does not display any of the correct paths. Typing cd "C:\\DOCUME~1\\Eric\\??\\folder" does not work either.
I’m having a problem running a shell command where the path of the shell command is on a Chinese system using Chinese encoding.
I have a folderitem which points to ‘C:\Documents and Settings\Eric\??\folder’. Folderitem.exists is True.
dim fpath as string = folderitem.shellpath
On my (British English) system:
fpath is “C:\DOCUME~1\Eric\263E~1\folder”
When I run: Shell.execute("cd "+fpath). It succeeds - Shell.ErrorCode=0
So far, so good.
When I run it on a Chinese system, however fpath retains it’s Chinese path and now always fails when passed as a path to shell.execute
“C:\DOCUME~1\Eric\??\folder”
When I run Shell.execute("cd "+fpath). It fails - Shell.ErrorCode=1. I can’t read Shell.Result as I can’t work out what encoding the result comes back as.
If I run cd "C:\\DOCUME~1\\Eric\\??\\folder" from a command prompt(cmd.exe) it works.
So, I either have an environmental variable problem (why does it work from cmd.exe?) or a path encoding issue.
Anyone have an idea?
I tried the ‘Interactive Shell’ example on the system and all the paths are a mess. Just typing dir does not display any of the correct paths. Typing cd "C:\\DOCUME~1\\Eric\\??\\folder" does not work either.
Lee[/quote]
I would look at nativepath to see if I can get the Dos name for ??. With some luck it will give you 263E~1.
A possible workaround since apparently shell does not stomach UTF-16 but Cmd does, would be to use a batch file which takes the path as argument and executes it through cmd.
I get “C:\DOCUME~1\Eric\??\folder” on their folder
and “C:\DOCUME~1\Eric\263E~1\folder” on mine.
NativePath gives:
“C:\Documents and Settings\Eric\??\folder”
Using dir /x on seems to show that the desktop folder does not have a shortname on either system, unlike (for example) ‘My Documents’ has a shortname of ‘MYDOC~1’
I’d had looked at the chcp page earlier and tried setting the chcp as one of the commands in the string but to no affect.
Their system returns chcp 936
I’ve just tried adding "cmd /u /c " to the beginning of the command (also cmd /c) but that did not work either when called from a Xojo shell. Exactly the same string, including the ‘cmd /u /c’ pasted into an open ‘cmd.exe /u’ window works fine.
I’ve tried various convert encoding values too on the string before running .execute as well.
I’d had looked at the chcp page earlier and tried setting the chcp as one of the commands in the string but to no affect.
Their system returns chcp 936
I’ve just tried adding "cmd /u /c " to the beginning of the command (also cmd /c) but that did not work either when called from a Xojo shell. Exactly the same string, including the ‘cmd /u /c’ pasted into an open ‘cmd.exe /u’ window works fine.
I’ve tried various convert encoding values too on the string before running .execute as well.
Lee[/quote]
Difficult to help since obviously I do not have a Chinese Windows
Last idea : try launching Cmd with the same parameters with FolderItem Launch. Since that will not be in the shell, it should execute just as it does manually.
This is the problem I have. the shortname is still “C:\DOCUME~1\Eric\??\folder” on the chinese system, not "C:\DOCUME~1\Eric\263E~1\folder, like I have on mine when I create a folder with that name. It’s weird but it looks like the Desktop folder is a special case and has no shortname either on my English XP, or on their Chinese one.
Tim - All the paths are definitely quoted.
Michel - this is exactly what I’m doing: Converting a folderitem into a shellpath to send to a shell.
Here’s a screenshot of an application I’ve written to test the paths.
This is what I have in the action event of the button.
dim f as folderitem = SelectFolder
if f<>nil then
self.Listbox1.AddRow(array("ShellPath",f.ShellPath))
self.Listbox1.AddRow(array("nativePath",f.NativePath))
dim s as new shell
dim st as string
st="dir /x """+f.ShellPath+""""
s.Execute(st)
self.Listbox1.AddRow(array("dir /x ShellPath",st,str(s.ErrorCode)+" "+s.Result.DefineEncoding(Encodings.SystemDefault).ConvertEncoding(encodings.UTF8)))
st=st.ConvertEncoding(encodings.SystemDefault)
s.Execute(st)
self.Listbox1.AddRow(array("dir /x ShellPath encoded",st,str(s.ErrorCode)+" "+s.Result.DefineEncoding(Encodings.SystemDefault).ConvertEncoding(encodings.UTF8)))
st="dir /x """+f.NativePath+""""
s.Execute(st)
self.Listbox1.AddRow(array("dir /x NativePath",st,str(s.ErrorCode)+" "+s.Result.DefineEncoding(Encodings.SystemDefault).ConvertEncoding(encodings.UTF8)))
st=st.ConvertEncoding(encodings.SystemDefault)
s.Execute(st)
self.Listbox1.AddRow(array("dir /x NativePath encoded",st,str(s.ErrorCode)+" "+s.Result.DefineEncoding(Encodings.SystemDefault).ConvertEncoding(encodings.UTF8)))
end if
The three columns show how the path string is created from the folderitem, the command sent to the shell and the result (shell.errorcode shell.Result).
Shell.errorcode = 1 when it fails and the Chinese shell.Result is ‘System cannot find the file specified’
Shell.errorcode = 0 when it succeeds and the Chinese shell.Result is the directory structure.
This shows that an ASCII shortname works ok, but a chinese one doesn’t.
Exactly the same command pasted into a cmd.exe window works.
[quote=186811:@Lee Badham]This is the problem I have. the shortname is still “C:\DOCUME~1\Eric\??\folder” on the chinese system, not "C:\DOCUME~1\Eric\263E~1\folder, like I have on mine when I create a folder with that name. It’s weird but it looks like the Desktop folder is a special case and has no shortname either on my English XP, or on their Chinese one.
Tim - All the paths are definitely quoted.
Michel - this is exactly what I’m doing: Converting a folderitem into a shellpath to send to a shell.[/quote]
You seem to have missed the most important part. I convert to a shellpath, then I DIR that shell path with the option /x that displays the Dos name.
Have you tried Dir /x, even just in the Command Prompt ? On an English system, at least, it displays the Dos name for a folder I created with name ??.
why would cd "C:\\DOCUME~1\\Eric\\??\\folder\" from a cmd.exe work
but
dim pathcommand as string = "cd """C:\\DOCUME~1\\Eric\\??\\folder\""""
//pathcommand checked to contain the correct quoted string
shell.execute(pathcommand)
not work?
Remember the only problem is with folders with no shortname but are still localised (such as C:\Documents and Settings\Eric\Desktop, which is actually C:\Documents and Settings\Eric\??)
Lee