$ curl -f "http://localhost/force_error.php" > /dev/null 2>&1 && echo Success || echo Fail
$ Fail
$ curl "http://localhost/force_error.php" > /dev/null 2>&1 && echo Success || echo Fail
$ Success
Created
December 18, 2015 05:53
-
-
Save freestrings/119ce3af72447db57834 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
http_response_code(500); | |
exit(1); |
This file contains hidden or 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
public class TestCurlProcess { | |
public static void main(String... args) throws Exception { | |
System.out.println("'-f' option exit code : " + execute("curl -f http://www.404.site")); // 6 | |
System.out.println("no option exit code : " + execute("curl http://www.404.site")); // 6 | |
System.out.println("-f option exit code : " + execute("curl -f http://localhost/force_error.php")); // 22 | |
System.out.println("no option exit code : " + execute("curl http://localhost/force_error.php")); // 0 | |
} | |
private static Integer execute(String cmd) throws Exception { | |
Process process = Runtime.getRuntime().exec(cmd, null); | |
Integer exitCode; | |
while (true) { | |
if (!process.isAlive()) { | |
exitCode = process.exitValue(); | |
break; | |
} | |
Thread.sleep(100); | |
} | |
return exitCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment