The space in Xojo software execution

Hello group, here I am again with one of my wonderful questions :slight_smile: 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))

What is this difference due to?

The only way to put a " in a string in Xojo is to use “”“” (that is " followed by another ") in the string, other than using " + chr( 34 ) + ".

s.Execute(“START /MAX " + LeggiRigoFileDiTesto(5) +” “”" +PathImmagine + “”“” )

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

In a Windows cmd line, the quotes go around the entire path, not just pieces of it.

1 Like

Excuse me Iva, but “”" what characters are they?

I wanted to directly write the Path in the execute command, but as you suggested (surely I misunderstood) it doesn’t work, it gives me an error.

s.Execute(“START /MAX C:\Test Paint\Path percorso 1\Ecco Qui\PaintTest\AvancePaint.exe ” “”" +PathImmagine + “”“” )

You need them around each path. In your example:

s.Execute(“START /MAX ""C:\Test Paint\Path percorso 1\Ecco Qui\PaintTest\AvancePaint.exe """ """ +PathImmagine + """" )

Is a shell every space is the end of that parameter. To prevent this " is used. Take a simple example:

Program One Two Three

Is a program with three parameters called “One”, “Two” and “Three”.

Program "One Two" Three

Is a program with two parameters “One Two” and “Three”.

It is always the same double quote character. You have to avoid ‘curly quotes’ which may get translated by certain software, including the forum.

the quote character is the chr(34) ??

Yes, the double quote. If I use the </> icon above, when posting, it isn’t manipulated:


It is the normal double quote you get when you press shift and that key on the keyboard. On a Mac it is above ', I think on Windows it is Shift-2 ".


i’ve done a lot of tests, I can’t start the application+attached file correctly… this quotes thing is really difficult for me.

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.

s.Execute(“START /MAX " + LeggiRigoFileDiTesto(5) +” "+PathImmagine)

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.

ApplicationPath = """C:\Test Paint\Path percorso 1\Ecco Qui\PaintTest\AvancePaint.exe"""

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.

cCMD = "START /MAX """ + LeggiRigoFileDiTesto(5) +""" """+PathImmagine + """"

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.

If you find this clearer, it will also work:

cCMD = "START /MAX " + chr(13) + LeggiRigoFileDiTesto(5)  + chr(13) + " "  + chr(13) + PathImmagine + chr(13)

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:

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"
1 Like

In the meantime, thank you for your availability.

LeggiRigoFileDiTesto(5) =C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe

I’m trying the codes you wrote. With

Dim cCMD as string
cCMD = "START /MAX """ + LeggiRigoFileDiTesto(5) +""" """+PathImmagine + """"

Nothing happens. It shows no signs of life.


Dim cCMD as string
cCMD = "START /MAX " + chr(13) + LeggiRigoFileDiTesto(5)  + chr(13) + " "  + chr(13) + PathImmagine + chr(13)

error is:

In MSDOS prompt i write:
START /MAX “”“C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe”“” “c:\Test.jpg”

or START /MAX “C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe” “c:\Test.jpg”

but not work.

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.

START /MAX "C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe" "c:\Test.jpg"

This one should work, assuming your paths and " are correct. They need to be " and not " or "

If you just paste this into the command line does the application start:

"C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe"

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:

Screenshot 2023-05-19 at 15.28.32

and not, these:

Screenshot 2023-05-19 at 15.28.56

/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.

Stupid me! This should be:

Dim cCMD as string
cCMD = "START /MAX " + chr(34) + LeggiRigoFileDiTesto(5)  + chr(34) + " "  + chr(34) + PathImmagine + chr(34)

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.

Are you sure of your paths.

"C:\Test Paint\Percorso percorso 1\Ecco Qui\PaintTest\AvancePaint.exe"

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)
s.Execute("START /MAX " + LeggiRigoFileDiTesto(5) +" "+PathImmagine)  'For SIMIL PAINT WORK