tags:

views:

161

answers:

3

Can we recognize which file is executable (i.e. chmod +x) using Mono under Linux? Is there any method in common .Net/Mono base class libraries?

Edit: native Linux executables

A: 

Though it's not exactly a method to find .NET executables, you can load the assembly with Assembly.Load. If it fails, it's not a .NET assembly.

OregonGhost
I told about native executables, not .Net assemblies
macropas
OK, the question was a little ambiguous in this regard. I thought it meant that you want to find files that can be executed using Mono under Linux.
OregonGhost
+1  A: 

Yes, we can, but I don't know of a common .NET class that does it. You could look at the mono sources. :)

Edit:

The original link refers to a helper application, which can't be found. However, the Mono Project page has something to say about binfmt support too, and no helper app seems to be required.

Rytmis
Unfortunately this link about detecting .Net or Wine executables and source of utility is inaccessible therewith.
macropas
Haha, I just realized I parsed the original question entirely wrong! I read that as which file is (executable using mono) rather than which file is executable (using mono). Sorry!
Rytmis
+4  A: 

The best you can do is use the Mono.Unix.Native namespace to check file permissions, I believe. You can check whether a file has executable permissions (for owner/group/others) by calling the Syscall.Stat method. More specifically, you'll want to look into the FilePermissions enum.

Noldorin
Small correction. Syscall.Stat - http://www.go-mono.com/docs/index.aspx?link=M%3aMono.Unix.Native.Syscall.stat
macropas
And in Windows we can identify executable file by its extension or analyzing its structure.
macropas