Hello group, here I am again with one of my wonderful questions I would like to set a Path for a photo editing program. At the moment I use windows Paint and everything works with the instruction:
Dim s as new shell
s.Execute("START /MAX " +LeggiRigoFileDiTesto(5)+" "+Chr(34) + PathImmagine + chr(34))
dove LeggiRigoFileDiTesto(5)=C:\Windows\System32\mspaint.exe
e PathImmagine=C:\Users\Federico\Desktop\TEST XOJO\MioMagazzino\BozzeDisegniProgetti\Test.jpg
Now my question is this, could I setup another photo editing program with a complex Path filled with spaces? For example: “C:\Test Paint\Path percorso 1\Ecco Qui\PaintTest\AvancePaint.exe”
I set this Path, but it would be possible to execute a program + the attached file whatever its path. With Paint if I edit the image the image opens in Paint, but with a different software I still can’t. At the moment I can run the program, manually adding the " when there are spaces. The above path would be:
“C:\“Test Paint”\“Path percorso”” 1"\“Ecco Qui”\PaintTest\AvancePaint.exe".
The software opens but the attached image won’t open.
Solutions ?
I made some attempts, I tried replacing the spaces with ^ and ` but not work.
i tried too .ConvertEncoding(Encodings.WindowsANSI) but not solve my problem,
and Chr(34) + + Chr(34).
After several attempts I managed to launch the photo editing program, enclosing each path with spaces in quotes, so C:\Test Paint\Path percorso 1\Ecco Qui\PaintTest\AvancePaint.exe it becomes C:\“Test Paint”\“Path percorso 1”\“Ecco Qui”\PaintTest\AvancePaint.exe and I am able to open the image of PathImage.
s.Execute(“START /MAX " + LeggiRigoFileDiTesto(5) +” " +PathImmagine
Now, if I replace the photo editing program with the paint path c:\windows\system32\mspaint.exe … the paint is launched but it doesn’t open the image.
To open the image I have to insert quotes with:
s.Execute(“START /MAX " + LeggiRigoFileDiTesto(5) +” "+Chr(34) + PathImmagine+ chr(34))
It is a bit confusing because of all the quotes. but to break it down a little:
” """ is broken down as follows:
" // Starts the literal string
space // adds a space to the string
"" // adds a single " to your string
" // closes the literal string
"""" is broken down as follows:
" // Open the literal string
"" // Add a quote
" // Close the literal string
It’s not the easiest thing in Xojo. Basically if you want a command line parameter to be “one item” and it has spaces in it you need to put quotes around it. To do that in Xojo within a literal string you need two " in a row. so:
MyString = "This is some text" ' is a string literal.
MyStringWithQuotes = "This is ""Some"" text" ' comes out as This is "Some" text
CommandLine = """c:\Program Files\SomeApplication\SomeProgram.exe"" /max ""c:\Some Path\Some File.txt"""
// Prevent the space between Program and Files from making a new parameter and prevent the space between Some and Path from making a new parameter.
PathImmagine=C:\Users\Federico\Desktop\TEST XOJO\MioMagazzino\BozzeDisegniProgetti
(It has a space in the directory name but it doesn’t cause problems, it opens the file.)
Now I should create something to replace the spaces in case there are any… could I use the replace on ReadLine(5)?
No, it only goes at the start and end of the item. For example The whole path is one thing. You do not have to deal with each space separately. There just needs to be one at the start of the item with spaces and one at the end.
or you can put them in the final string. I would suggest that you create a string and then pass it to the s.Execute method, so you can test it is correct by copy and pasting into the command line.
You can then look at cCMD in the debugger and make sure it looks right, you can even copy and paste it into a command line and see if it runs the way you want.
This is not just a Xojo problem. If you typed this into the command line without the quotes it would not work either.
Your command has four parts:
Start
/Max
PathToTheProgram ' This has spaces in it so needs "" around it
PathToTheFile ' This has spaces in it so needs "" around it
// So you need:
Start /Max "PathToTheProgram" "PathToTheFile"
When you post command lines or any code highlight it and press the </> button in the toolbar of the post window. That will ensure that quotes do not get changed to 66 and 99 style quotes.
I’ve not used windows in a long time, what is the “/MAX” supposed to do. Is it an option of Start or of the program? Ah, star the program in a maximised window.
Also worth testing, what happened in you open that folder and double click the AvancePaint.exe?
All the quotes on the command line, and in Xojo, must look like this:
/MAX is to open the window to the maximum size.
Yes double quote, is the character char(34), SHIFT+2. But it doesn’t work…the only way it works for me is by double quote, for each part of the path that has the space . I’ve read several things and many say this. Since it works, now I see how to implement a function that reads the Path, for each Folder Name between \ , checks if there is a space and for each space it adds the double quote… Vat, thanks a lot, but no solution apart from that it’s fine, I don’t want to waste your time, it’s not a necessary thing, it was my curiosity about how Xojo manages spaces in paths … I can easily do without it.
Other languages use \ as an indicator of a special character to follow. So "\ " (backslash space) would mean ignore the space and treat it as part of the name. That doesn’t work for Xojo and I’m pretty sure it doesn’t work for MSDOS. It never used to anyway. It would work for Mac and Linux.
has Percorso twice in a row? What happened when you pasted just that into the command line.
Spaces in paths are not a Xojo problem. They are an MSDOS problem. Shell effectively just operates as it there was an invisible MSDOS prompt and sends it commands.
even so it doesn’t work, it doesn’t run any programs.
When I pasted the command into MSDOS nothing happened, nothing booted. It works only if in the Path I put the double quotes ■■■■+2 in the path names with spaces.
Can you paste exactly what you are saying works when pasted into the command line, pressing the </> button after highlighting it. It makes no sense given how the MSDOS prompt works, unless I’m misunderstanding you.
In DOS PROMPT, if i write: START /MAX C:"Test Paint""Path percorso"" 1""Ecco Qui"\PaintTest\AvancePaint.exe C:\Users\Federico\Desktop\TEST_XOJO\MioMagazzino\BozzeDisegniProgetti\Image.jpg it work fine.
and I also noticed that there are differences to run two different programs correctly, The first line is for windows Paint, the second for a very similar alternative program
s.Execute("START /MAX " + LeggiRigoFileDiTesto(5) +" "+chr(34)+PathImmagine+chr(34)) 'For PAINT - Work but need chr(34)