# Problem with shell execute

**URL:** <https://forum.xojo.com/t/problem-with-shell-execute/75726>\
**Category:** General\
**Created:** [May 12, 2023, 8:57am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726 "2023-05-12T08:57:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 12, 2023, 8:57am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/1 "2023-05-12T08:57:01Z")

</div>

Hi group, I have a problem with shell execute.  
I write like this:

```auto
Dim s as new shell 
s.Execute("START C:\Program Files (x86)\OpenOffice 4\program\scalc.exe")
```

and I get an error when opening. Depends on the path format which has spaces ?  
 ![error](https://forum.xojo.com/uploads/default/original/2X/d/db92c0a630731e22787e394e293db65ab9453785.png)

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [May 12, 2023, 9:12am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/2 "2023-05-12T09:12:56Z")

</div>

> [@Federico\_Giannetti](#):
>
> `s.Execute("START C:\Program Files (x86)\OpenOffice 4\program\scalc.exe")`

Try:

```auto
s.Execute("START " + Chr(34) + "C:\Program Files (x86)\OpenOffice 4\program\scalc.exe" + Chr(34))

```

Chr(34) = "  
The spaces in the path prevent execution. 😉

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 12, 2023, 9:14am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/3 "2023-05-12T09:14:01Z")

</div>

```auto

s.Execute("START " + """C:\Program Files (x86)\OpenOffice 4\program\scalc.exe""")

```

or

`s.Execute( "START " + chr(34) + " C:\Program Files (x86)\OpenOffice 4\program\scalc.exe" + chr(34))`

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [May 12, 2023, 9:16am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/4 "2023-05-12T09:16:30Z")

</div>

Or:

**There are three different ways you can escape file paths on Windows:**

- By enclosing the path (or parts of it) in double quotation marks ( ” ).
- \*By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn’t seem to work with every command.)
- \*By adding a grave accent character ( ` ) before each space. (This only works in PowerShell, but it always works.)

So, a

```auto
s.Execute("START C:\Program Files (x86)\OpenOffice 4\program\scalc.exe").ReplaceAll(" ","^ ")

```

could also work. 😃

\*Source: [https://www.howtogeek.com/694949/how-to-escape-spaces-in-file-paths-on-the-windows-command-line/](https://www.howtogeek.com/694949/how-to-escape-spaces-in-file-paths-on-the-windows-command-line/)

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [May 12, 2023, 12:35pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/5 "2023-05-12T12:35:02Z")

</div>

> [@Sascha\_S](#):
>
> The spaces in the path prevent execution.

Windows command line syntax rules - the very definition of Technical Debt 😃

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 12, 2023, 1:28pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/6 "2023-05-12T13:28:45Z")

</div>

> [@Sascha\_S](#):
>
> `s.Execute("START C:\Program Files (x86)\OpenOffice 4\program\scalc.exe").ReplaceAll(" ","^ ")`

The format would have been perfect, but the ReplaceAll doesn’t work

I tested the other examples … but they don’t work. I state that the OpenOffice Path from which I want to run the Calc is that, and it’s right. If I run the commands, the Command Prompt opens, with the right Path of the file in the window title, but the location it points to is Windows/system32

```auto

's.Execute("START C:\Program` Files (x86)\OpenOffice` 4\program\scalc.exe") NO WORK
's.Execute("START " + Chr(34) + "C:\Program Files (x86)\OpenOffice 4\program\scalc.exe" + Chr(34)) OPEN A DOS PROMPT WINDOW
's.Execute("START " + """C:\Program Files (x86)\OpenOffice 4\program\scalc.exe""") OPEN A DOS PROMPT WINDOW
's.Execute( "START " + chr(34) + " C:\Program Files (x86)\OpenOffice 4\program\scalc.exe" + chr(34)) OPEN A DOS PROMPT WINDOW
's.Execute("START C:\Program Files (x86)\OpenOffice 4\program\scalc.exe").ReplaceAll(" ","^ ") NOT WORK, error in .ReplaceAll
```

I was used this command with PAINT and it work fine:

```auto
Dim s as new shell 
s.Execute("START /MAX %windir%\system32\mspaint.exe "+Chr(34) + PathImmagine + chr(34))
```

but now, I am not able to open openoffice calc.

 ![sample](https://forum.xojo.com/uploads/default/original/2X/2/23d77611505b2a43677542b126350bccf3912dcd.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 12, 2023, 2:16pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/7 "2023-05-12T14:16:45Z")

</div>

> [@Federico\_Giannetti](#):
>
> `C:\Program Files (x86)\OpenOffice 4\program\scalc.exe`

Have you considered just launching the app?

```auto

Dim f as folderitem
f = getfolderitem("C:\Program Files (x86)\OpenOffice 4\program\scalc.exe")
if f = nil then 
msgbox "the path is invalid or the file does not exist"
else

if f.exists then
   f.launch
else
  msgbox "the file does not exist"
end if

end if

```

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 12, 2023, 4:33pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/8 "2023-05-12T16:33:53Z")

</div>

> [@Jeff\_Tullin](#):
>
> Have you considered just launching the app?
> 
> ```auto
> Dim f as folderitem
> f = getfolderitem("C:\Program Files (x86)\OpenOffice 4\program\scalc.exe")
> if f = nil then 
> msgbox "the path is invalid or the file does not exist"
> else
> 
> if f.exists then
> f.launch
> else
> msgbox "the file does not exist"
> end if
> 
> end if
> 
> ```

Actually NO, I didn’t know you could use f.launch.  
So launch the application. Now the question is: can I also attach the file to be opened together with the app? In the meantime, I’m going to read the documentation.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 12, 2023, 4:40pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/9 "2023-05-12T16:40:31Z")

</div>

> [@Federico\_Giannetti](#):
>
> can I also attach the file to be opened together with the app?

The question always changes after the answer. 🙂

if you have a document, and SCALC.exe is the default app which opens it in Windows (association), then just launch the actual document file instead.  
or use

```auto
start somedoc.someextension

```

If SCALC is NOT the default app, then you are back to a command line solution.

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 12, 2023, 4:48pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/10 "2023-05-12T16:48:52Z")

</div>

> [@Jeff\_Tullin](#):
>
> `start somedoc.someextension`

You’re right… the problem is that I don’t know all the commands and I try to do what I need with what little I know. Then, asking for advice, I understand that instead there is so much more than what I think … I thought (as I did for the PAINT) to launch the calc app and attach the file I needed … but there is no I managed. Now you’ve directed me to another path … I understand what you told me but I don’t understand how it works … I certainly have to study. In my case the .xls files I open with calc, so it’s the default app … for now I would like to leave the path of “start somedoc.someextension” and go back to f.launch. But is it possible to open the file I need together with the APP? (Basically I have an xls file that I have to open when I press a button)

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 12, 2023, 4:54pm UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/11 "2023-05-12T16:54:31Z")

</div>

> I have an xls file that I have to open when I press a button

```auto
Dim f as folderitem
f = specialfolder.documents.child("myfile.xls")
if f = nil then 
msgbox "the path is invalid or the file does not exist"
else

if f.exists then
   f.launch
else
  msgbox "the file does not exist"
end if

end if

```

[/quote]

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 13, 2023, 8:08am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/12 "2023-05-13T08:08:52Z")

</div>

> [@Jeff\_Tullin](#):
>
> ```auto
> Dim f as folderitem
> f = specialfolder.documents.child("myfile.xls")
> if f = nil then 
> msgbox "the path is invalid or the file does not exist"
> else
> 
> if f.exists then
> f.launch
> else
> msgbox "the file does not exist"
> end if
> 
> end if
> 
> ```

Thanks Jeff, I thought you should open the application + file… I discovered a new thing.

```auto
Dim f as folderitem
f = specialfolder.documents.child(LeggiRigoFileDiTesto(4))
if f = nil then 
  msgbox "the path is invalid or the file does not exist"
else
  
  if f.exists then
    f.launch
  else
    msgbox "the file " + LeggiRigoFileDiTesto(4) +" does not exist"
  end if
 
end if
```

The path read by LeggiRigoFileDiTesto(4) is “C:\Users\Federico\Desktop\ListinoHF.xls”

I’ve been careful to remove all the special characters, but it says it can’t find the file. But the file is right there. Where am I wrong?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [May 13, 2023, 8:26am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/13 "2023-05-13T08:26:15Z")

</div>

> [@Federico\_Giannetti](#):
>
> the problem is that I don’t know all the commands

So: read the documentation (they used RTFM in the old times, but there are no more manuals nowadays…)

When dealing with files, read [FolderItem](https://documentation.xojo.com/api/files/folderitem.html#folderitem)

Or your [LOCAL] documentation if you use a pre Xojo 2019 version. Set that in the preferences.

PS: yes, I know, it is a boring task.

The look vary depending on the Xojo IDE version, but:

 ![image](https://forum.xojo.com/uploads/default/original/2X/6/6616e8cd4b282b9a7c321de6675b81b020666bc6.png)

If you set the preferences to the local (or built-in as in the screen shot) documentation, you will get the documentation that is for your running Xojo version.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 13, 2023, 8:34am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/14 "2023-05-13T08:34:46Z")

</div>

> [@Federico\_Giannetti](#):
>
> I’ve been careful to remove all the special characters,

What special characters?  
If you take any characters out, you can easily break it.  
If there are _accented_ characters, (eg ç , å ) they may be unicode characters, and you may not be retaining them in your text file.

Please **screenshot the value of LeggiRigoFileDiTesto(4) in the debugger** before you do anything with the characters.  
Also **screenshot the folder contents as they appear in Windows,** so that we can see the actual filename and location.  
**Show us the contents of the file which is parsed by LeggiRigoFileDiTesto**

And finally, is that folder synched by OneDrive or Dropbox?  
The file may not actually be available immediately.  
But it’s almost certain that the filename is not correct.

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 13, 2023, 8:43am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/15 "2023-05-13T08:43:23Z")

</div>

> [@Federico\_Giannetti](#):
>
> ```auto
> Dim f as folderitem
> f = specialfolder.documents.child(LeggiRigoFileDiTesto(4))
> if f = nil then 
> msgbox "the path is invalid or the file does not exist"
> else
>   
> if f.exists then
> f.launch
> else
> msgbox "the file " + LeggiRigoFileDiTesto(4) +" does not exist"
> end if
>  
> end if
> 
> ```

I was saying that there are no special characters, so the error cannot be attributed to them, the problem will be somewhere else. I am attaching the various screenshots.  
File desktop position:

 ![0 Posizion](https://forum.xojo.com/uploads/default/original/2X/7/7d426f43cbd12c45a8dca5cda3db3559e10bed37.png)  
My text file … i read row n°4.  
 ![1 TextFile](https://forum.xojo.com/uploads/default/original/2X/3/389efba254e3f9e5562c5223f09f821f48459ea2.png)  
Verifing path read  
 ![2 Read Path File](https://forum.xojo.com/uploads/default/original/2X/f/f0bdcb885f0dc72c9e2e9f94189a7dc16d0e7c7c.png)  
Error. File non find.  
 ![3 Error file read](https://forum.xojo.com/uploads/default/original/2X/5/52d9905c5a79ad820cdd4a3e01e43a8a84c2cb98.png)

The problem occurs even i write : f = specialfolder.documents.child(“C:\Users\Federico\Desktop\ListinoHF.xls”)

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [May 13, 2023, 8:53am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/16 "2023-05-13T08:53:11Z")

</div>

> [@Federico\_Giannetti](#):
>
> The problem occurs even i write

Of course !

Read the documentation first, then write the commands !

You use a path to the DOcuments folder and then pyou add a full path to elsewhere ! Even a human can have troubles reading that.

If the file is in the Desktop folder, use that (if exist, check the doc): SpecialFolder.Desktop?Child(“ListinoHF.xls”)

capice ?

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [May 13, 2023, 9:05am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/17 "2023-05-13T09:05:51Z")

</div>

The windows screenshot says the path is c:\utenti.…

Maybe that’s the problem?

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 13, 2023, 9:06am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/18 "2023-05-13T09:06:42Z")

</div>

> [@Emile\_Schwarz](#):
>
> SpecialFolder.Desktop?Child

You’re right Emile, it’s that I’m not a programmer, I wrote something in VB6 and for some things it’s difficult for me to understand the logic of Xojo.  
Ok I solved it, at least it seems, by setting f = specialfolder.UserHome.Child(“\Desktop\ListinoHF.xls”).  
(P.S: I referred to the guide [https://documentation.xojo.com/api/files/specialfolder.html](https://documentation.xojo.com/api/files/specialfolder.html))

But my question is this: Can I set a Path to be read? In the sense that the.xls file that I have to open can also be found on a network PC.

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [May 13, 2023, 9:08am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/19 "2023-05-13T09:08:58Z")

</div>

> [@Federico\_Giannetti](#):
>
> f = specialfolder.UserHome.Child(“\Desktop\ListinoHF.xls”).

Jeff  
i solved with:  
f = specialfolder.UserHome.Child(“\Desktop\ListinoHF.xls”).

I seem to have understood from what I’ve read, that the FolderItem has preset Paths, which can be recalled… Ex: Templates, System, UserHome…etc…etc… as per the documentation. But can’t I set a path without having to refer to the preset ones?  
…what if the file is located on a network folder or c:\folder1\folder2 ?

---

<div class="post-metadata">

**Author:** ![PaulS](https://forum.xojo.com/user_avatar/forum.xojo.com/pauls/32/199_2.png) [@PaulS](https://forum.xojo.com/u/PaulS)\
**Post date:** [May 13, 2023, 9:12am UTC](https://forum.xojo.com/t/problem-with-shell-execute/75726/20 "2023-05-13T09:12:37Z")

</div>

> Blockquote

> [@Federico\_Giannetti](#):
>
> `f = specialfolder.UserHome.Child(“\Desktop\ListinoHF.xls”)`

You can even make easier it by using desktop directly.  
`f = SpecialFolder.Desktop.Child(“ListinoHF.xls”)`

[Next page](https://forum.xojo.com/t/problem-with-shell-execute/75726.md?page=2)
