Launching windows app from txt file path

Hi all,
Any help welcomed. I am an IT admin with limited coding experience, so can’t see where I have gone wrong.
I am trying to create a simple app launcher (to lockdown a desktop PC)
I have managed successfully to use a hardcoded path, which is fine right now.
However I would like to finish the job and move to a simple txt file in the same folder as the launcher that contains the path. this way if a new version of the program lands with a different path I dont have to re-code, just change the text file.
my current attempt :-

Dim f As FolderItem
Dim axp As String
f = SpecialFolder.UserHome.child(“axpath.txt”)
// All the file types in this set
if f <> nil and f.exists then
Dim t As TextInputStream
Try
t = TextInputStream.Open(f)
t.Encoding = Encodings.MacRoman
axp = t.ReadAll
Catch e As IOException
t.Close
MsgBox(“Error accessing file.”)
End Try
end if
Dim ax As New Shell
ax.Execute axp

Does not error during build, equally doesnt actually run the software.

Any help gratefully received.

This is a Mac app… right?

Hi Brandon,

No windows 10.

Many thanks

Encoding is probably wrong. I don’t recall the syntax for using the default system encoding and I’m on my phone. Look it up and give it a try.

i guess you have a EndOfLine.CRLF in your text file?
it seems Execute do not want it.
and it seems that Execute accept spaces in path.

put your source into a method and then call this method in a button or by menu for a test.

encoding is usually utf8 or ansi.

if you save it with notepad it could add a byte order mark at first.

So…

Just delete that line, or change it to the actual encoding the text file has, the default encoding for text files in Windows is WindowsANSI.

Have you considered that the path might be wrong, or contain a space?
Are you storing the ShellPath or the NativePath?

Also, if axpath.txt is missing, ax.Execute axp is getting executed anyway…
axp could be empty!

You do a ‘readall’… are there more than one apps you want to launch?
because you dont loop through the lines, you just use the whole file at once here

try:

Dim f As FolderItem
Dim axp As String
Dim t As TextInputStream

f = SpecialFolder.UserHome.child(“axpath.txt”)
if f <> nil and f.exists then

Try
t = TextInputStream.Open(f)
axp = t.ReadLine   //first line only here.. use a loop if there are more
t.Close
Catch e As IOException

t.Close
MsgBox(“Error accessing file.”)
End Try

    if axp <> "" then
        Dim ax As New Shell
        ax.Execute axp
    end if
else
     msgbox "Unable to locate axpath.txt"
end if





Put a breakpoint on this statement and step over it, then see what axp contains.

1 Like

Hi All,
Many thanks for all your help.
It would appear removing the “t.encoding” line was a help,
However, the text file being in the same location as the program needed
f = SpecialFolder.UserHome.child(“axpath.txt”)
Changed to :-
f = SpecialFolder.CurrentWorkingDirectory.child(“axpath.txt”)
once I realised the SpecialFolder had options I was able to work out my mistake.
Thanks again for the assistance, and hope me posting the solution helps someone else out in the future.

f = SpecialFolder.CurrentWorkingDirectory.child(“axpath.txt”)

If that’s where you keep the file, do not attempt to write to it.
That will fail.
You should put the file into

SpecialFolder.ApplicationSupport.child(“MyApp”).(“axpath.txt”)

Hi Jeff,
Thankfully only reading the file for a path, which is working.
But thank you for clarifying for anyone else having the issues I did.