Programming in ruby: can I understand I'm on Linux??
-
- Level 1
- Posts: 7
- Joined: Sat Sep 25, 2010 10:23 am
Programming in ruby: can I understand I'm on Linux??
Hi all, I'm programming in ruby inside SkehctUp8. My script, of course, is for the Windows version of SketchUp: I need to start a third *.exe from my code, but I can't run well. As a workaround I think it's better to run the native Linux versione of that software: is there a way to understand my script is running inside wine rather that the real Windows SO??
Re: Programming in ruby: can I understand I'm on Linux??
You want a Windows program in Wine to launch a native Linux program.
There is neither a reliable way to detect Wine nor is there an official "API" function of Wine to do this. But you can start with two assumptions: a default install of Wine comes with a symbolic link "Z:" to root "/". And a default install of Wine includes the winepath.exe program. This should work for everyone except users who intentionally locked down Wine (and those users know what they do).
So a solution to find Wine is:
You should also do feature-testing, ie. check that all programs exist that your script requires, for example:
A Linux program can be started the same way as a Windows program by calling its executable:
You also need to make sure to convert file paths between Unix and Windows, and best without assuming a specific Wine prefix.
It is more difficult to get return data back (Ruby back ticks with return value is broken).
Take a look at the plugin Texture Resizer, that does all that (it uses native ImageMagick on Linux because that's where ImageMagick runs fastest).
There is neither a reliable way to detect Wine nor is there an official "API" function of Wine to do this. But you can start with two assumptions: a default install of Wine comes with a symbolic link "Z:" to root "/". And a default install of Wine includes the winepath.exe program. This should work for everyone except users who intentionally locked down Wine (and those users know what they do).
So a solution to find Wine is:
Code: Select all
File.exists?("C:/Windows/system32/winepath.exe" || File.exists?("Z:/usr/bin/wine")
Code: Select all
File.exists?("Z:/bin/bash")
Code: Select all
path = "C:/Users/MyName/photo.jpg"
system("Z:/usr/bin/gimp `wine winepath.exe -u '#{path}'`")
It is more difficult to get return data back (Ruby back ticks with return value is broken).
Take a look at the plugin Texture Resizer, that does all that (it uses native ImageMagick on Linux because that's where ImageMagick runs fastest).