command-line-interface

How can I “intercept” Ctrl+C in a CLI application?

安稳与你 提交于 2019-11-26 03:57:14
How can I intercept Ctrl + C (which normally would kill the process) in a CLI (command line interface) Java application? Does a multi-platform solution exist (Linux, Solaris, Windows)? I'm using Console 's readLine() , but if necessary, I could use some other method to read characters from standard input. VonC Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ } }); This should be able to intercept the signal, but only as an intermediate step before the JVM completely shutdowns itself, so it may not be what you are looking after. You need to use

Can one executable be both a console and GUI application?

为君一笑 提交于 2019-11-26 03:27:55
问题 I want to make a C# program that can be run as a CLI or GUI application depending on what flags are passed into it. Can this be done? I have found these related questions, but they don\'t exactly cover my situation: How to write to the console in a GUI application How do I get console output in C++ with a Windows program? 回答1: Jdigital's answer points to Raymond Chen's blog, which explains why you can't have an application that's both a console program and a non-console * program: The OS

Is it possible to create a remote repo on GitHub from the CLI without opening browser?

爱⌒轻易说出口 提交于 2019-11-26 03:19:06
问题 I created a new local Git repository: ~$ mkdir projectname ~$ cd projectname ~$ git init ~$ touch file1 ~$ git add file1 ~$ git commit -m \'first commit\' Is there any git command to create a new remote repo and push my commit to GitHub from here? I know it\'s no big deal to just fire up a browser and head over to Create a New Repository, but if there is a way to achieve this from the CLI I would be happy. I read a vast amount of articles but none that I found mention how to create a remote

What is the canonical way to determine commandline vs. http execution of a PHP script?

两盒软妹~` 提交于 2019-11-26 02:50:02
问题 I have a PHP script that needs to determine if it\'s been executed via the command-line or via HTTP, primarily for output-formatting purposes. What\'s the canonical way of doing this? I had thought it was to inspect SERVER[\'argc\'] , but it turns out this is populated, even when using the \'Apache 2.0 Handler\' server API. 回答1: Use the php_sapi_name() function. if (php_sapi_name() == "cli") { // In cli-mode } else { // Not in cli-mode } Here are some relevant notes from the docs: php_sapi

Using django for CLI tool

若如初见. 提交于 2019-11-26 02:14:55
问题 Is there any sense in using Django framework for developing Command Line Interface tool? In my case there won\'t be any graphical interface. What benefits can I get using it? Or maybe you know any other useful frameworks for CLI? I\'d like to put an accent on making HTTP requests with REST API. UPDATE: Thanks guys! I would like rather to use REST API than create it in my tool. 回答1: While django is primarily for web apps it has a powerful and easy to use ORM that can be used for CLI apps as

How can I “intercept” Ctrl+C in a CLI application?

冷暖自知 提交于 2019-11-26 01:15:08
问题 How can I intercept Ctrl + C (which normally would kill the process) in a CLI (command line interface) Java application? Does a multi-platform solution exist (Linux, Solaris, Windows)? I\'m using Console \'s readLine() , but if necessary, I could use some other method to read characters from standard input. 回答1: Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ } }); This should be able to intercept the signal, but only as an intermediate step

grep a file, but show several surrounding lines?

被刻印的时光 ゝ 提交于 2019-11-25 23:47:36
问题 I would like to grep for a string, but also show the preceding five lines and the following five lines as well as the matched line. How would I be able to do this? 回答1: For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for the number of lines after the match. grep -B 3 -A 2 foo README.txt If you want the same number of lines before and after you can use -C num . grep -C 3 foo README.txt This will show 3 lines before and 3 lines after. 回答2: -A and -B will

Does PHP have threading?

烈酒焚心 提交于 2019-11-25 23:21:07
问题 I found this PECL package called threads, but there is not a release yet. And nothing is coming up on the PHP website. 回答1: There is nothing available that I'm aware of. The next best thing would be to simply have one script execute another via CLI, but that's a bit rudimentary. Depending on what you are trying to do and how complex it is, this may or may not be an option. 回答2: From the PHP manual for the pthreads extension: pthreads is an Object Orientated API that allows user-land multi

Execute a command line binary with Node.js

时光怂恿深爱的人放手 提交于 2019-11-25 22:29:42
问题 I am in the process of porting a CLI library from Ruby over to Node.js. In my code I execute several third party binaries when necessary. I am not sure how best to accomplish this in Node. Here\'s an example in Ruby where I call PrinceXML to convert a file to a PDF: cmd = system(\"prince -v builds/pdf/book.html -o builds/pdf/book.pdf\") What is the equivalent code in Node? 回答1: For even newer version of Node.js (v8.1.4), the events and calls are similar or identical to older versions, but it