Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
program p
implicit none
character(len=:),allocatable :: s
integer :: stat,l,i,j,k
call get_command_argument (0,length=l)
allocate(character(len=l) :: s)
call get_command_argument (0,s,status=stat)
if (stat == 0) then
i=index(s,'/',back=.true.)
j=index(s,'\',back=.true.)
k=max(i,j)
if(k.ne.0)s=s(k+1:)
print *, "The program's name is " // trim (s)
endif
end program p
var s = process.argv0;
String s = System.getProperty("sun.java.command");
s = arg[0]
$s = $_SERVER['PHP_SELF'];
s := ExtractFileName(ParamStr(0));
my $s = $0;
s = $0
s = __FILE__
let s = std::env::current_exe()
.expect("Can't get the exec path")
.file_name()
.expect("Can't get the exec name")
.to_string_lossy()
.into_owned();
fn get_exec_name() -> Option<String> {
std::env::current_exe()
.ok()
.and_then(|pb| pb.file_name().map(|s| s.to_os_string()))
.and_then(|s| s.into_string().ok())
}
fn main() -> () {
let s = get_exec_name().unwrap();
println!("{}", s);
}