Skip to content

Commit 15887b0

Browse files
Merge pull request #3 from anshumanjadiya1102/ItTakesNothing
Implement new commands like `MoveCommand` & `LsCommand`
2 parents c1496b2 + cd738eb commit 15887b0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.io.BufferedReader;
2+
import java.io.InputStreamReader;
3+
4+
public class PingCommand {
5+
public static void main(String[] args) {
6+
if (args.length < 1) {
7+
System.out.println("Usage: java PingCommand <hostname>");
8+
return;
9+
}
10+
11+
String host = args[0];
12+
13+
try {
14+
// Run the ping command
15+
Process process = Runtime.getRuntime().exec("cmd.exe /c ping " + host);
16+
17+
// Read the output of the ping command
18+
BufferedReader reader = new BufferedReader(
19+
new InputStreamReader(process.getInputStream())
20+
);
21+
22+
String line;
23+
while ((line = reader.readLine()) != null) {
24+
System.out.println(line);
25+
}
26+
27+
// Wait for the process to finish
28+
int exitCode = process.waitFor();
29+
System.out.println("Ping command exited with code: " + exitCode);
30+
31+
} catch (Exception e) {
32+
System.out.println("Error executing ping command.");
33+
e.printStackTrace();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)