Hostname: Difference between revisions

add JavaScript, ws
(→‎{{header|OCaml}}: ++ GNU Octave)
(add JavaScript, ws)
Line 23:
print(("hostname: ", hostname, new line))</lang>
=={{header|AutoHotkey}}==
<lang AutoHotkey>MsgBox % A_ComputerName </lang>
</lang>
 
=={{header|AWK}}==
Line 52 ⟶ 51:
#+sbcl (machine-instance)
#+clisp (let ((s (machine-instance))) (subseq s 0 (position #\Space s)))
#-(or sbcl clisp) (error "get-host-name not implemented")) </lang>
</lang>
 
{{libheader|CFFI}}
Line 82 ⟶ 80:
=={{header|Forth}}==
{{works with|GNU Forth|0.7.0}}
<lang forth>include unix/socket.fs
include unix/socket.fs
 
hostname type </lang>
</lang>
 
=={{header|Fortran}}==
Line 121 ⟶ 117:
 
=={{header|Java}}==
<lang java>import java.net.*;
import java.net.*;
 
class DiscoverHostName {
Line 132 ⟶ 127:
}
}
} </lang>
}
 
</lang>
=={{header|JavaScript}}==
{{works with|JScript}}
<lang javascript>var network = new ActiveXObject('WScript.Network');
var hostname = network.computerName;
WScript.echo(hostname);</lang>
 
=={{header|MATLAB}}==
Line 156:
Similarly to [[Discover the Hostname#MATLAB|MATLAB]], we could call system command <tt>hostname</tt> to know the hostname. But we can also call the internal function <tt>uname()</tt> which returns a structure holding several informations, among these the hostname (nodename):
 
<lang octave>uname().nodename </lang>
uname().nodename
</lang>
 
=={{header|Perl}}==
Line 192 ⟶ 190:
=={{header|R}}==
Sys.info provides information about the platform that R is running on. The following code returns the hostname as a string.
<lang R>Sys.info()[["nodename"]] </lang>
<lang R>
Sys.info()[["nodename"]]
</lang>
Note that Sys.info isn't available on all platforms. As an alternative, you can call an OS command. The following code prints the hostname to the console (or other connection), but returns an int.
<lang R>system("hostname") </lang>
system("hostname")
</lang>
 
=={{header|Ruby}}==
Line 233 ⟶ 227:
=={{header|Ursala}}==
The user-defined hostname function ignores its argument and returns a string.
<lang Ursala>#import cli
#import cli
 
hostname = ~&hmh+ (ask bash)/<>+ <'hostname'>!</lang>
Anonymous user