Last active
May 8, 2021 23:05
-
-
Save kalloc/307ae7c9ce6d2924e895d393833c7c5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.lang.ProcessBuilder; | |
import java.util.concurrent.TimeUnit; | |
public class Main { | |
public static void main(String[] args) { | |
// create a new list of arguments for our process | |
String[] list = {"bash", "-c", "yes Syntax Warning: Length in linearization table is invalid | head -n 10000 >&2"}; | |
// create the process builder | |
ProcessBuilder processBuilder = new ProcessBuilder(list); | |
processBuilder.redirectErrorStream(false); | |
InputStream inputStream = null; | |
String line = null; | |
try { | |
Process p = processBuilder.start(); | |
inputStream = new BufferedInputStream(p.getInputStream()); | |
// Reads first byte from file | |
int i = inputStream.read(); | |
while (i != -1) { | |
System.out.print((char) i); | |
i = inputStream.read(); | |
} | |
if (!p.waitFor(5, TimeUnit.SECONDS)) { | |
p.destroy(); | |
p.waitFor(); | |
} | |
inputStream.close(); | |
} catch (Exception e) { | |
System.out.println("Some exception"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment