FAQ Database Discussion Community

## Expanding variables in a Windows batch file

batch-file,command-line-arguments,batch-processing,command-prompt
I run the following command in a Windows batch file: start "" "C:\PDF Viewer\PDFXCview.exe" /A "page=1&zoom=33.3" "G:\my pdfs\file 1.pdf" /A "page=4&zoom=55.5" "G:\my pdfs\file 2.pdf" The works perfectly fine and opens both PDF files using their respective parameters. However, to make the process cleaner, I would like to start using variables...

## What are some use cases of “$*” in bash? bash,parameters,arguments,command-line-arguments From the bash man page: "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. "[email protected]" is equivalent to "$1" "$2" ... Any example where "[email protected]" cannot work in place of "$*"?... ## Use$^I and supply arguments

perl,file,command-line,command-line-arguments

## Accessing option data

python,command-line-arguments,options
I am trying to add an option to a Python program like so: optionParse= argparse.ArgumentParser(description='Change Number of Locations') optionParse.add_argument('-n') The -n option will allow the user to specify a number that will be used in the program. They will input it like this: myProgram.py -n 12 How would I access...

## Linux how to pass date command's output as input for a python program as command line argument

python,linux,pipe,command-line-arguments
I am quite a newbie to Linux. I have a very simple Python script that accepts command line arguments and prints them. Now I just want to pass the date command's output as input to this Python script and print it. The Python script looks like this. import sys print...

## How to run pytest.main(“-v test_script2.py”) when test_script2.py needs some command line arguments in order for the test functions to run?

python,command-line-arguments,py.test
I have two scripts. One script parses all the arguments and decides the control flow of the script. Another script has all the test functions defined and I wanted to use pytest module to invoke the 'test_script2.py' and run all the tests. But there are some arguments that I need...

## how do I know what n(positive integer) is when user types ./a.out -n?

c,command-line-arguments
How do I make an command line argument a variable? That is, for example, how do I know what n(positive integer) is when user types ./a.out -n? I know I can use strcmp(argv[1], "-1") strcmp(argv[1], "-100") but is there a simpler way to implement this?...

## Python Command Line Arguments: Calling a function

python,command-line,command-line-arguments,argparse,optparse
So I'm stuck on a project I'm working on that involves the command line in python. So basically, here's what I'm trying to accomplish: I have a set of functions in a class, say, def do_option1(self, param1, param2) : #some python code here def do_option2(self, param1): #some python code here...

## Test if string represents “yyyy-mm-dd”

c++,command-line-arguments
I am working on a program that takes two command line arguments. Both arguments should be dates of the form yyyy-mm-dd. Since other folks will be using this program and it will be requesting from mysql, I want to make sure that the command line arguments are valid. My original...

## How to embed commandline arguments in a execution command?

python,c++,command-line-arguments
I need to pass the commandline arguments of my C++ code as the commandline arguments of my python script. My code looks like: int main(int argc,char * argv[]) { FILE *in; char buff[512]; cout<<argv[1]; string str = "python comparescript.py "+argv[1]+" "+argv[2]+" "+argv[3]; if(!(in = popen(str, "r"))){ cout<<"Image Comparison made successful";...

## Command line option for PuTTY (Windows) to set action of mouse buttons to xterm?

windows,command-line-arguments,putty
As per the title, I'm looking for a command line option which will have the effect of clicking xterm under "Window > Selection > Control use of mouse" in the PuTTY configuration window. I can't see anything in the standard command line options in the PuTTY docs and I'm trying...

## Maven install not respecting command line arguments

java,maven,command-line-arguments,pom.xml
I have a project which I am attempting to install with maven. The pom.xml has a few properties in it which are modified when the maven install command is run depending on whatever version of a library we are attempting to build with: <properties> <some-version>0</some-version> </properties> The zero here is...

## Parsing exclusive groups in Python

python,command-line-arguments,argparse

## Parsing command-line entries in C: implementing a shell

c,shell,command-line,command-line-arguments,command-line-parsing
I'm implementing a shell in C, and I ran into some problems parsing command-line entries. I want my parser method to separate command-line entries that are delimited by the whitespace character, and return the result as a double char pointer. ie, say I have "ls -l >ls.txt", my parser should...

## How do I show processes for a specific uid or username using command line in python?

python,process,command-line-arguments
for opt, arg in opts: if opt in ('-u'): arg = numuid ps = subprocess.Popen('ps -u ', shell=True, stdout=subprocess.PIPE) print ps.stdout.read() this is what i have so far, numuid is supposed to go after ps -u and is the uid. but what do i do to have it read in...

## Passing array of arguments to Quartz Scheduler

java,command-line-arguments,quartz-scheduler
I am trying to add a Quartz Scheduler to an existing Java class. The class uses String[] args as input from the main function. public static void main(String[] args) { //validate(args); summarizeData(args); } But then the Java class implements Job, and it has to use the execute method which only...

## Give command line argument (c++)

c++,command-line-arguments
This is a Robot Car program, which has gangsters and cops who catch them. How can I give the number of cops with command line argument? Here is the code (myshmclient.cpp): #include <myshmclient.hpp> char data[524288]; std::vector<justine::sampleclient::MyShmClient::Gangster>justine::sampleclient::MyShmClient::gangsters ( boost::asio::ip::tcp::socket & socket, int id, osmium::unsigned_object_id_type cop ) { boost::system::error_code err; size_t length...

## passing arguments to a cURL shell script file

python,shell,curl,command-line-arguments
I do not have much experience with shell or python scripts so I am looking for some help on how I can accomplish this. Goal: Pass arguments to a shell or python script file that will be used to perform either a cURL Post request or a python post request....

## Running executable files using Haskell

Say there's a C++ code that I've compiled into an executable using: g++ test.cpp -o testcpp I can run this using Terminal (I'm using OS X), and provide an input file for processing inside the C++ program, like: ./testcpp < input.txt I was wondering if doing this is possible, from...

## Dealing with backslash as a command line argument in Python

python,string,command-line-arguments,backslash
I know about escaping backslashes in programming. However I'm passing in a command line argument into a Python program to parse. Whitespace is irrelevant, however via the command line, whitespace does matter. So I am trying to concatenate all argv[] arguments except the first element into a string to then...

## bash interactive script pass input

bash,command-line-arguments
I'm running the following interactive Jar. java -jar script.jar argument-line-here \n Now I'm creating a bash script which runs the jar file. How do I pass the argument line and the conformation "\n" to this interactive script? these are input lines for the script. This question has some answers, expect...

## Parameter checks in bash not testing correctly

linux,bash,command-line,command-line-arguments
I've been scratching my head about this for a while... I'm trying to get my code to react like: If no parameters, go to menu If more OR less than 4 parameters, call error and go to menu If exactly 4 parameters, write to file and exit I can't get...

## How to Use Command Line Arguments to Dictate Flow of Program?

java,methods,command-line-arguments
I have scoured all of Google it seems and I cannot find anything regarding how to use command line arguments to tell the Java program which subsequent method to perform. I am trying to create a Java program with several different aspects of a student grading application. The main program...

## Options not parse as Argument in Unix

bash,command-line-arguments,getopt,getopts

## bash getopts validate options

linux,bash,scripting,command-line-arguments,getopts
I have following code in bash script: # argument validation and usage help usage() { cat << EOF usage: $0 options File Integrity Monitoring Script: OPTIONS: -b input file for [backup] -r input file for [diff report] -l list backup files EOF } if [$# -eq 0 ] then...

## How to pass Ctrl+Enter command to Process when using C# StandardInput redirection

c#,process,cmd,command-line-arguments,pos-tagger
Im trying to make C# application that uses hunpos tagger. Runing hunpos-tag.exe requires three input arguments: model, inputFile, outputFile In cmd it would look something like this: hunpos-tag.exe model <inputFile >outputFile Although, hunpos-tag.exe can be run with just the model, at that point it'll wait for text input (from cmd)...

## Writing text into and retrieving text from the text file using command line auguments

c++,text,command-line,command,command-line-arguments
Hello I want to write the output of my C++ Program in a text file using Command Line Argument then afterward retrieve it from the file . can you help me please I cannot get a satisfying code help.

## Python argparse a list input

python,command-line-arguments,argparse
The code below accepts command line arguments for mode such as -m fizz and -m fizz bazz. This, as expected, passes the arguments to the main function as ['fizz', 'bazz'] (for the second example above). It seems user-unfriendly to pass command line arguments with spaces, so I'd like argparse to...

## How to run another file using command prompt and continue with the rest of steps without waiting for the file to be closed

batch-file,command-line,command,command-line-arguments,command-prompt
I came across a strange scenario where it works intermittently. Requirement: Need to back date the system date before running a file and once the file is ran the system date should be reverted to the current date. I have written a code which works for one of the file...

## How to make “if” condition change automatically depending on Command Line Argument in Java?

java,if-statement,command-line-arguments
In my code, if condition should change depending on command line argument. For example in the code below: int a = Integer.parseInt(args[0]); for (int i = 0; i < 100000; i++) { if (a == 2) if ((i % 25 == 0) || ((i+1) % 25 == 0) // do...

## Xcode won't pass arguments to C++ executable

c++,xcode,debugging,command-line-arguments
I'm attempting to debug a C++ project using Xcode. My program looks for input through stdin like so: string line; getline(cin, line); I have an input file called input.txt that I normally pass into the executable like so: ./verti < input.txt In order to accomplish the same thing while debugging...

## Testing for pipe or console standard input with ARGF

ruby,input,command-line-arguments
I have written a script that I would like to take input either from a pipe or by providing a filename as an argument. ARGF makes it easy to deal with this flexibly, except in the incorrect usage cases where neither is provided, in which case STDIN is opened and...

## sys.argv is different depending on the method of invocation of script

python-2.7,command-line-arguments
I have a simple Python script that all it does is: import sys print sys.argv When I open cmd and type MyScript.py arg1 I get: ['C:\\MyScript.py'] But when type: python MyScript.py arg1 I get: ['C:\\MyScript.py', 'arg1'] I've looked around here but did not find my answer. I've uninstalled and re-installed...

## How can I append the values from an input file to the command line options using argparse?

python,command-line-arguments,argparse
Say I have a yaml input file (input.txt) that contains the following: names: [Bob, Jill] ages: [22, 31] county: somewhere my code to parse this: import yaml import argparse parser = argparse.ArgumentParser() parser.add_argument('--name', default=[], dest='names', action='append') parser.add_argument('--age', default=[], dest='ages', action='append') parser.add_argument('--county', dest='county') parser.add_argument( '--config-file', dest='config_file', type=argparse.FileType(mode='r')) args = parser.parse_args() print...

## Passing multiple arguments as comman line args

arrays,vb.net,command-line-arguments
I am calling one .NET app from another using Process.Start and passing in a bunch of strings as command line arguments: startInfo.Arguments = String.Join(""" """, MyArray) Dim p As Process = Process.Start(startInfo) My intent is to pass in something like: "first value" "second value" "third value" and retrieve from within...

## Adjust exception message basing on missing information

python,python-2.7,command-line-arguments,python-2.x,command-line-parsing
Having such code: if __name__ == "__main__": parser.add_argument("--u_shape_dict", default="", action='store', help="required for ...") parser.add_argument("--v_shape_dict", default="", action='store', help="required for ...") u_shape_dict = args['u_shape_dict'] if not u_shape_dict: raise Exception('u_shape_dict is missing. Please provide it') v_shape_dict = args['v_shape_dict'] if not v_shape_dict: raise Exception('v_shape_dict is missing. Please provide it') I want to combine this...

## Why does my program not check the number of arguments correctly?

c,command-line-arguments,binary-search-tree,stderr
Okay so I am writing code for a binary search tree that must read in strings from an input file: "input.txt" and I am trying to feed my program command line arguments. My program is supposed to take two command line args, the name of the program then the name...

## Run python script with some of the argument that are optional

python,command-line-arguments,argparse,sys
I have gone through the sys documentation, however there is something that is still unclear to me. I have looked for some similar question on stackoverflow, but I haven't find anything useful (clearly any reference is appreciated!). I want to create a script - say foo.py - in which I...

## CMake: Adding command line arugments to project

cmake,command-line-arguments
My question is somewhat similar to this SO but not the same. I created a HelloWorld program with the following: add_executable( HelloWorld \${SRC} ) When I generate a project file (for example a Visual Studio .sln file, or a XCode .xcodeproj file). I want to hit the run button and...

## How to correctly quote a command with parameters in a Windows batch file

batch-file,command-line-arguments,batch-processing,command-prompt
I am attempting to open multiple PDF files in multiple tabs in multiple windows using PDF X-Change Viewer, which has command line options. All PDF files listed in the same line open within the same window. To allow the script to proceed without waiting for the windows created on each...

## Segfault for invalid long option

c,segmentation-fault,command-line-arguments,getopt,getopt-long
I have the following code: struct option longopts[] = { {"version", no_argument, 0, 'v'} }; if (argc > 1) { int c; int longindex; while ((c = getopt_long (argc, argv, "v", longopts, &longindex)) != -1) { switch (c) { case 'v': puts (VERSION_INFO); exit (0); case '?': exit (1); }...