Jump to content

Fork: Difference between revisions

1,114 bytes added ,  6 years ago
Added Kotlin
No edit summary
(Added Kotlin)
Line 690:
</pre>
 
=={{header|Kotlin}}==
{{trans|NetRexx}}
<lang scala>// version 1.1.51
 
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.IOException
 
fun main(args: Array<String>) {
try {
val pb = ProcessBuilder()
val currentUser = pb.environment().get("USER")
val command = listOf("ps", "-f", "U", currentUser)
pb.command(command)
val proc = pb.start()
val isr = InputStreamReader(proc.inputStream)
val br = BufferedReader(isr)
var line: String? = "Output of running $command is:"
while(true) {
println(line)
line = br.readLine()
if (line == null) break
}
}
catch (iox: IOException) {
iox.printStackTrace()
}
}</lang>
 
Sample output (Ubuntu 14.04):
<pre>
Output of running [ps, -f, U, alan] is:
UID PID PPID C STIME TTY STAT TIME CMD
user1 1382 1370 0 23:09 ? Ss 0:00 init --user
.....
user1 5297 2592 0 23:49 pts/5 Sl+ 0:00 java -jar Fork.jar
user1 5309 5297 0 23:49 pts/5 R+ 0:00 ps -f U user1
</pre>
 
=={{header|Lasso}}==
9,488

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.