command-line-arguments

How to test the passing of arguments in Golang?

假如想象 提交于 2019-12-30 04:06:21
问题 package main import ( "flag" "fmt" ) func main() { passArguments() } func passArguments() string { username := flag.String("user", "root", "Username for this server") flag.Parse() fmt.Printf("Your username is %q.", *username) usernameToString := *username return usernameToString } Passing an argument to the compiled code: ./args -user=bla results in: Your username is "bla" the username that has been passed is displayed. Aim: in order to prevent that the code needs to be build and run manually

Handle spaces in argparse input

為{幸葍}努か 提交于 2019-12-30 01:36:12
问题 Using python and argparse, the user could input a file name with -d as the flag. parser.add_argument("-d", "--dmp", default=None) However, this failed when the path included spaces. E.g. -d C:\SMTHNG\Name with spaces\MORE\file.csv NOTE: the spaces would cause an error (flag only takes in 'C:SMTHNG\Name' as input). error: unrecognized arguments: with spaces\MORE\file.csv Took me longer than it should have to find the solution to this problem... (did not find a Q&A for it so I'm making my own

Arguments passed into for loop in bash script [duplicate]

半世苍凉 提交于 2019-12-30 00:26:05
问题 This question already has answers here : Variables in bash seq replacement ({1..10}) [duplicate] (7 answers) Closed last year . I am trying to pass the argument as max limit for the for loop like this: #!/bin/bash for i in {1..$1} do echo $i done This however returns {1..2} when called with argument 2 , instead of executing the script and giving me 1 2 回答1: Variable substitutions are not done inside of curly braces. You can use fixed numbers but not variables. Brace Expansion A sequence

Allow positional command-line arguments with nargs to be seperated by a flag

烈酒焚心 提交于 2019-12-29 01:34:47
问题 I have a program using argparse. It takes 1 required positional argument, 1 optional positional argument, and 1 flag argument. Something like: usage: test.py [-h] [-a A] b [c] So, I tried using this: parser = argparse.ArgumentParser() parser.add_argument('-a') parser.add_argument('b') parser.add_argument('c', nargs='?', default=None) print(parser.parse_args()) Which works fine for test.py B C -a A and test.py -a A B C . But when I do test.py B -a A C , it throws an error: $ python3 test.py B

Parsing/passing command line arguments to a bash script - what is the difference between “$@” and “$*”?

女生的网名这么多〃 提交于 2019-12-28 16:08:07
问题 I am using a bash script to call and execute a .jar file from any location without having to constantly enter its explicit path. The .jar requires additional variable parameters to be specified at execution, and as these can be anything, they cannot be hard coded into the script. There are 3 variables in total, the first specifies 1 of 2 actions that the .jar is to make, the second specifies a target file to enact this action on and the third specifies the name of a file that the action is to

How do I run a program with commandline arguments using GDB within a Bash script?

只愿长相守 提交于 2019-12-28 03:16:08
问题 When running a program on GDB, usually, the arguments for the program are given at the run command. Is there a way to run the program using GDB and as well as give arguments within a shell script? I saw an answer in a related question, mentioning that we can attach GDB to the program after the script starts executing. But then I will have to 'wait' the program. Is there another way to do this? 回答1: You can run gdb with --args parameter, gdb --args executablename arg1 arg2 arg3 If you want it

ImageMagick Command-Line Option Order (and Categories of Command-Line Parameters)

那年仲夏 提交于 2019-12-28 03:04:27
问题 My supervisor has asked me to convert the parts of our Perl scripts that use PerlMagick to instead pipe and use the command line version of ImageMagick (for various unrelated reasons). Using the our existing interface (crop, scale, save, etc) I'm building up a list of operations the user wants to perform on an image, constructing the statement to pipe and then executing it. What I would like to know is: Are convert operations performed from left to right? ie the order I pass them What happens

Is char *envp[] as a third argument to main() portable

不羁岁月 提交于 2019-12-27 10:53:15
问题 In order to get an environment variable in a C program, one could use the following: getenv() extern char **environ; But other than the above mentioned, is using char *envp[] as a third argument to main() to get the environment variables considered part of the standard? #include <stdio.h> int main(int argc, char *argv[], char *envp[]) { while(*envp) printf("%s\n",*envp++); } Is char *envp[] portable? 回答1: The function getenv is the only one specified by the C standard. The function putenv,

bash: Execute a string as a command

爱⌒轻易说出口 提交于 2019-12-25 16:56:19
问题 See my previous question on assembling a specific string here. I was given an answer to that question, but unfortunately the information didn't actually help me accomplish what I was trying to achieve. Using the info from that post, I have been able to assemble the following set of strings: gnuplot -e "filename='output_N.csv'" 'plot.p' where N is replaced by the string representation of an integer. The following loop will explain: (Actually, there is probably a better way of doing this loop,

Java program terminates before completion of command in batch file

与世无争的帅哥 提交于 2019-12-25 07:59:20
问题 I am trying to exceute batch file from a Java program. The batch file has a command which connects to IBM RTC then gets some data which takes around 30 seconds. But the program is exiting just after the command is run without waiting for the output. public static void main(String[] args) { final String scmCommand = "cmd /c D:\\Coverage\\SCMHistory.bat"; try { Process process = Runtime.getRuntime().exec(scmCommand); /* * final InputStream in = process.getInputStream(); int ch; * while((ch = in