command-line-interface

Format text output for console in Java

谁说我不能喝 提交于 2019-12-06 00:17:05
I'm writing a simple diary console program. Can't really figure out what the easiest way to break up text input from the user. I take in a diary note in a string and then I want to be able to print that string to the console, but unformatted it of course just shows the string in one long line across the terminal making it terribly unfriendly to read. How would I show the string with a new line for every x characters or so? All I can find about text formatting is System.out.printf() but that just has a minimum amount of characters to be printed. I would recommend to use some external libraries

CLI with nodejs

流过昼夜 提交于 2019-12-05 23:36:52
I'm developing a CLI in node that will be published to NPM. Since it's a CLI application, I want it to be included in the path once it's installed, so it's not require to type "node my-app.js" to run it. I want it to run with only "my-app". In the package.json, I'm including: "bin": { "my-all" : "./my-app.js" }, But this makes fail the installation via NPM with this error Error: ENOENT, chmod '/home/user1/node_modules/my-app/my-app' Assuming you're on some kind of unix (linux, osx), put this line at the top of your script: #!/usr/bin/env node Also make sure you set the file to executable (

Ionic build android in CLI does nothing

泄露秘密 提交于 2019-12-05 23:18:07
I really tried to avoid having to ask this question but I've been stuck on this for a good two days. The problem is that when I try to run the command " ionic build android " I get nothing. No error response, no warning, nothing. I installed node.js and made my npm global so I can access it anywhere. I installed ionic and cordova via npm install and I was able to start the application and see it on the web but when I try to run it on my device, I don't get any response at all. What am I missing? I have all the android sdks as I normally write my android applications natively. I installed Ant

“sort filename | uniq” does not work on large files

半城伤御伤魂 提交于 2019-12-05 22:30:54
I can remove duplicate entries from small text files, but not large text files. I have a file that's 4MB. The beginning of the file looks like this: aa aah aahed aahed aahing aahing aahs aahs aal aalii aalii aaliis aaliis ... I want to remove the duplicates. For example, "aahed" shows up twice, and I would only like it to show up once. No matter what one-liner I've tried, the big list will not change. If It type: sort big_list.txt | uniq | less I see: aa aah aahed aahed <-- didn't get rid of it aahing aahing <-- didn't get rid of it aahs aahs <-- didn't get rid of it aal ... However, If I copy

how to pass in the user-data when launching AWS instances using CLI

隐身守侯 提交于 2019-12-05 21:46:42
问题 I'm using the AWS CLI to launch instances, and the command is: aws ec2 run-instances what i'm expecting is to pass in a script as the user-data. so, I did: DATA= base64 ./my_script on my Mac OSX, and then pass the DATA by: aws ec2 run-instances --user-data $DATA BUT, nothing happened after the instance launched So, how exactly should I do? Thanks!! 回答1: There is no need to base64 encode the data yourself. You can prefix a file name/path with file:// So, aws ec2 run-instances --user-data file:

Windows alternative to pexpect

不羁岁月 提交于 2019-12-05 21:01:41
问题 I'm trying to write a cross-platform tool that runs specific commands, expects certain output for verification, and sends certain output (like username/password) for authentication. On Unix, I have been successful in programming a Python tool that uses the pexpect library (via pip install pexpect ). This code works perfectly and is exactly what I am trying to do. I've provided a small excerpt of my code for proof-of-concept below: self.process = pexpect.spawn('/usr/bin/ctf', env={'HOME'

PHP 5 second countdown (CLI, not JavaScript)

試著忘記壹切 提交于 2019-12-05 20:58:03
I am writing a PHP CLI (command line) script that will do some irreversible damage if it is run by accident. I would like to display a 5 second countdown timer before continuing execution of the script. How can I do this with PHP? To add my two cents, here's how you can add a confirmation prompt. <?php echo "Continue? (Y/N) - "; $stdin = fopen('php://stdin', 'r'); $response = fgetc($stdin); if ($response != 'Y') { echo "Aborted.\n"; exit; } $seconds = 5; for ($i = $seconds; $i > 0; --$i) { echo $i; usleep(250000); echo '.'; usleep(250000); echo '.'; usleep(250000); echo '.'; usleep(250000); }

Is there a way to open files with Notepad++ in Bash on Ubuntu on Windows?

不想你离开。 提交于 2019-12-05 19:05:32
I am on Windows 10 but I am using Bash on Ubuntu on Windows (WSL) to familiarize myself with the Linux command line. I am trying to take full advantage of its capabilities and was thinking it would be awesome to be able to open, say, index.html from the CLI in Notepad++. Is this possible? If so, how would I go about setting it up? I am pretty new to the command line in general, much less Linux commands. It is absolutely possible to use Notepad++ in WSL. In fact, you can use it in precisely the same way as if working in a normal Windows environment. You need to create a bash alias to allow for

php's command line option parsing, howto

北城以北 提交于 2019-12-05 18:34:45
I'm using Console_Getopt in PHP 5.2, and finding it surprising about how different it is from getopt in other languages (perl, bash, java). Can anyone recommend how to parse the args from the array "$opts" returned? php myprog.php -a varA -c -b varB $o= new Console_Getopt; $opts = $o->getopt($argv, "a:b:c"); print_r($opts); // the print_r returns below Array ( [0] => Array ( [0] => Array ( [0] => a [1] => varA ) [1] => Array ( [0] => c [1] => ) [2] => Array ( [0] => b [1] => varB ) ) [1] => Array ( ) ) I started doing something like below, which is long-winded, so I'm looking for suggestions

Copy file to backup directory preserving folder structure

耗尽温柔 提交于 2019-12-05 18:24:42
I have to copy a file in a directory, to its backup directory, preserving the folder structure. E.g. the file aaa in MyFolder/Test/aaa to .MyFolder.bck/Test/aaa I tried to use cp --parents MyFolder/Test/aaa .MyFolder.bck; But the result is .MyFolder.bck/MyFolder/Test/aaa and not .MyFolder.bck/Test/aaa (which is the one I want). You need to cd to the directory and then copy the file: (cd MyFolder && cp --parents Test/aaa ../.MyFolder.bck) The brackets around the command make it run in a subshell, rather than in your current shell. The advantage of this is that it saves you from having to cd