command-line-interface

Is there any way to know if a php script is running in cli mode?

孤街醉人 提交于 2019-12-09 02:54:41
问题 ... or the other way around, is there any way to know if a php script is running inside a web server? 回答1: http://www.php.net/manual/en/function.php-sapi-name.php function is_cli() { return php_sapi_name() === 'cli'; } 回答2: Typically, when running in CLI mode, the superglobals $argv and $argc will be set, and many of the typical contents of $_SERVER (e.g. request method) won't be available. In addition, pre-defined console streams such as STDIN , STDOUT and STDERR will be set up. 回答3: You

How to upgrade from Kohana 3.2 to 3.3 (implementing PSR-0)?

纵然是瞬间 提交于 2019-12-09 01:38:18
问题 What steps do I need tot take to upgrade from Kohana 3.2 to 3.3 with respect to the implementation of PSR-0 and what commands have to be executed from the command line? 回答1: Unix command line: These are the steps I took to implement PSR-0 in my Kohana application. I removed the following system/ dir: rm -rf system In your current bootstrap.php the only change is to make the classes start with an upper, so best is to keep your old bootstrap and just change the following lines on top of the

Test whether the actual output is a terminal or not in node.js

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 00:22:47
问题 I'm writing a command line interface for one of my programs, and I would like to use the colorized output of winston if it's appropriate (the output is a terminal and it's not redirected to a file). In bash it can be done with the -t test as this SO answer correctly says. But I'm looking for the node.js alternative for testing this. 回答1: Similarly to the bash examples you link to, Node has the 'tty' module to deal with this. To check if output is redirected, you can use the 'isatty' method.

argparse optional value for argument

早过忘川 提交于 2019-12-08 19:22:57
问题 I want to distinguish between these three cases: The flag is not present at all python example.py ; The flag is present but without a value python example.py -t ; and The flag is present and has a value python example.py -t ~/some/path . How can I do this with Python argparse ? The first two cases would be covered by action='store_true' but then the third case becomes invalid. 回答1: You can do this with nargs='?': One argument will be consumed from the command line if possible, and produced as

How to pass STDIN to node.js child process

社会主义新天地 提交于 2019-12-08 18:48:33
问题 I'm using a library that wraps pandoc for node. But I can't figure out how to pass STDIN to the child process `execFile... var execFile = require('child_process').execFile; var optipng = require('pandoc-bin').path; // STDIN SHOULD GO HERE! execFile(optipng, ['--from=markdown', '--to=html'], function (err, stdout, stderr) { console.log(err); console.log(stdout); console.log(stderr); }); On the CLI it would look like this: echo "# Hello World" | pandoc -f markdown -t html UPDATE 1 Trying to get

How do I start jupyter notebook from command-line to run in my current directory, without editing config files or passing hard paths?

不羁的心 提交于 2019-12-08 18:47:49
Juypter notebook currently has a limitation: Starting terminal in current directory How do I do this from command-line (no Anaconda or other GUI), without the following unacceptable hacky approaches? (and in particular where the notebook directory might well change between invocations, or between users?) Manually edit the hard path into your jupyter notebook config file, in the c.NotebookApp.notebook_dir parameter Embed hard paths into your notebook code. Must be absolute paths. (yukky). Also user-dependent. Can't distribute notebooks which handle files properly with paths relative to their

pcntl_fork() returning, Fatal error: Call to undefined function pcntl_fork()

谁都会走 提交于 2019-12-08 15:46:26
问题 I'm trying to fork a command line run XAMPP php process using pcntl_fork(). When I run the command below: $pid = pcntl_fork(); if($pid == -1){ file_put_contents('testlog.log',"\r\nFork Test",FILE_APPEND); return 1; //error } else if($pid){ return 0; //success } else{ file_put_contents($log, 'Running...', FILE_APPEND); } I get: Fatal error: Call to undefined function pcntl_fork() Can anyone suggest how to fix this? 回答1: It is not possible to use the function 'pcntl_fork' when PHP is used as

How can I get PHP to use the same APC cache when invoked on the CLI and the web?

倖福魔咒の 提交于 2019-12-08 15:27:01
问题 I'm using APC to cache user variables (with the apc_store/apc_fetch commands). I've also enabled APC for the CLI with the option "apc.enable_cli = 1". However, the CLI version of PHP seems to access a different APC cache from the version used by Apache. Is it possible to configure APC to use the same cache for both CLI and web invocations? 回答1: Not possible.. The only way to accomplish something like what your asking is to use something like memcacheD. Or run what you need to run through your

How can I suppress the headers from CLI CURL's output of request

旧时模样 提交于 2019-12-08 14:42:17
问题 There's plenty of info on how to prevent curl from showing header information when doing a request for the PHP version, but seemingly nothing for the CLI version. my request is in the form curl -i -X POST -H 'Content-Type: application/json; charset=UTF-8' -H 'X-Accept: application/json' -H '-d '{"somedata":"12ihiuhihihed994f63dbef6b012b"}' https://myurl.com/v3/oauth/request Which works, but returns this: HTTP/1.1 200 OK Cache-Control: private Content-Type: application/json Date: Wed, 27 Mar

The doskey command separator produces blank lines

為{幸葍}努か 提交于 2019-12-08 13:24:02
问题 The doskey command separator ( $T ) generates a blank line when the command produces no output. C:\> set "a=" C:\> set "b=" C:\> doskey test=set "a=foo" $T set "b=bar" $T echo ^%a^% ^%b^% C:\> test C:\> C:\> foo bar Note the blank line after issuing test , which affects readability. There is a well-known ^? alternative to $T , which does not add blanks, but the new command does not inherits environment variables. C:\> set "a=" C:\> set "b=" C:\> doskey test=set "a=foo" ^& set "b=bar" ^& echo