How can I pass parameters from the command line to $_POST in a PHP script?

Just insert the following lines at the beginning of your script: /* If started from the command line, wrap parameters to $_POST and $_GET */ if (!isset($_SERVER[“HTTP_HOST”])) { parse_str($argv[1], $_GET); parse_str($argv[1], $_POST); } This small piece of code does the trick (you may decide if you want to use $_GET or $_POST or, like I … Read more

Set max_execution_time in PHP CLI

The documentation says that when running in command line mode, the default is 0 (unlimited). It doesn’t say that you cannot override it: set_time_limit(10); // this way ini_set(‘max_execution_time’, 10); // or this way Edit: I just tried it myself, and it works as expected. F:\dev\www>c:php -f index.php PHP Fatal error: Maximum execution time of 2 … Read more

Why does my C# array lose type sign information when cast to object?

UPDATE: I’ve used this question as the basis for a blog entry, here: https://web.archive.org/web/20190203221115/https://blogs.msdn.microsoft.com/ericlippert/2009/09/24/why-is-covariance-of-value-typed-arrays-inconsistent/ See the blog comments for an extended discussion of this issue. Thanks for the great question! You have stumbled across an interesting and unfortunate inconsistency between the CLI type system and the C# type system. The CLI has the concept of … Read more

How do I edit a file after I shell to a Docker container?

As in the comments, there’s no default editor set – strange – the $EDITOR environment variable is empty. You can log in into a container with: docker exec -it <container> bash And run: apt-get update apt-get install vim Or use the following Dockerfile: FROM confluent/postgres-bw:0.1 RUN [“apt-get”, “update”] RUN [“apt-get”, “install”, “-y”, “vim”] Docker images … Read more

PHP CLI: How to read a single character of input from the TTY (without waiting for the enter key)?

The solution for me was to set -icanon mode on the TTY (using stty). Eg.: stty -icanon So, the the code that now works is: #!/usr/bin/php <?php system(“stty -icanon”); echo “input# “; while ($c = fread(STDIN, 1)) { echo “Read from STDIN: ” . $c . “\ninput# “; } ?> Output: input# fRead from STDIN: … Read more

How to cartoon-ify an image programmatically?

Here’s some algorithms to play with: Median or repeated box blur filter to obtain cartoonish color palette Edit: Bilateral filtering should suit your needs even better Min filter (zeroth percentile) to enhance some types of edges Color image segmentation using either small subcube or sphere in the RGB color cube Generic edge enhancement on segmented … Read more

Start-Process with PowerShell.exe exhibits different behavior with embedded single quotes and double quotes

js2010’s helpful answer is correct in that the use of Start-Process is incidental to your question and that the behavior is specific to PowerShell’s CLI (powershell.exe for Windows PowerShell, and pwsh for PowerShell (Core) 6+): On Windows[1], there are two layers of evaluation to consider: (a) The initial parsing of the command line into arguments. … Read more