Fork: Difference between revisions
Content added Content deleted
No edit summary |
(Added Kotlin) |
||
Line 690: | Line 690: | ||
</pre> |
</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}}== |
=={{header|Lasso}}== |