How to find out %COMPUTERNAME% and %USERNAME% ??
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
What the title says.
How do I find out on which machine (computer) MATLAB is running? (Windows CMD variable %COMPUTERNAME%)
How do I find out the name of the user who is logged in? (Windows CMD variable %USERNAME%)
The Matlab help is of no use since none of the search terms "user name", "machine name" and "hostname" lead me to anything useful...
many thanks in advance!
0 Kommentare
Antworten (5)
Daniel Shub
am 1 Sep. 2011
With java you can do this in an OS independent manner:
char(java.lang.System.getProperty('user.name'));
char(java.net.InetAddress.getLocalHost.getHostName);
1 Kommentar
Ken Atwell
am 1 Sep. 2011
GETENV is a somewhat more "graceful" way to do this:
getenv('COMPUTERNAME')
0 Kommentare
Fangjun Jiang
am 1 Sep. 2011
or
getenv('username')
getenv('computername')
2 Kommentare
Walter Roberson
am 7 Jan. 2017
This works fine on osx: it gives back the empty string in both cases, which is exactly what is appropriate when asked to provide system specific information. The question was not about how to fetch the username and computer name on Windows, it was about how to access those particular variables.
The osx equivalent variables are USER and HOSTNAME . USER should be available on on shells, but HOSTNAME might not be available if you have reconfigured the default system shell to csh or you dug out an old sh source somewhere and compiled that and made it your default system shell. Posix does not mandate that the environment variable exists... but the default shell for osx does define it.
I am not sure what the default shell is for the various Linux systems. I am sure it is not csh, but I cannot promise it is ksh or bash instead of sh.... Posix does mandate some shell features that were in ksh but not in sh, but that doesn't matter to Linux systems because Linux is not Posix.
Siehe auch
Kategorien
Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!