Detect system information - Linux

How can I get my application to determine which system it’s running on? I use Linux Mint and right now I have some functions that will write or read files to a directory and I have both systems coded but when on the dev system I have to uncomment the dev paths and comment the production paths, then when I build I have to make sure I comment the dev paths and uncomment the production paths.

I want the application to detect with system it’s on and select according to the system the correct path.

you can possibly call a shell command to get the hostname of the running system? Assuming dev and prod have a different name? Something like this:

Var sh as NEW Shell
Var result as string

sh.Execute("hostname")
result = sh.Result

if result = "hostname_of_prod" then
 ....
else // dev system
 ...
end if

In any case the shell is likely your friend, for this case of challenges. Try solving it in “in Linux” first and then execute this shell command from within your Xojo program via the shell …

1 Like

I thought shell was going to be the answer but wasn’t quite sure. I’ll give that a whirl after I finish some other stuff and let you know if this solves the question! Thank you!

1 Like

Hmm, okay I am getting a return value but when I test for it to select the code I want to run it doesn’t work…

Var strSystem As String = modSysFunc.mthSystemId // Get current working system...

If( strSystem = "mcdians-devtop" ) Then
  file = GetFolderItem( "/home/ian/Documents/The Nursery/Hours Export").Child( cboEmpId.Value.ToText + " Wage Hours.txt" )
ElseIf( strSystem = "jhgc_shoptop" ) Then
  file = GetFolderItem( "/home/jhgc_staff/Documents/The Nursery/Hours Export").Child( cboEmpId.Value.ToText + " Wage Hours.txt" )
Else
  MessageBox( "This function cannot work as you are not on a validated system." )
  Exit
End If

When I step through in debug mode I am seeing the correct hostname returned but the else statement executes and not the If statement… this one has me confused as it’s a simple If then Else…

debug_data

Here is a capture of the debug data…

Hmm, I am completely stumped!? Even though the return value matches the If condition it falls through to the Else statement. I tried commenting the Else statement and the code just stopped. This doesn’t make sense why the if statement is failing. So I tried a select statement and same thing, falls through to the Case Else.

I have 6 areas this is supposed to be used and it’s not working in any of them. And as you can see in the image in the above post, strSystem has my system name in it so the data is being obtained and returned.

John, you should inspect the string for extraneous spaces. If they exist, you can use the Trim function.

1 Like

Hmm, I’ll try Trim. I did look for spaces as that was my first thought… could be a carriage return maybe?

Hmmm, thanks! That worked!

2 Likes

Happy to help!

1 Like

You might want to try

System.VersionData.ToString()

1 Like