command-line-arguments

Pass in a value into Python Class through command line

大兔子大兔子 提交于 2019-12-22 08:52:42
问题 I have got some code to pass in a variable into a script from the command line. I can pass any value into function for the var arg. The problem is that when I put function into a class the variable doesn't get read into function . The script is: import sys, os def function(var): print var class function_call(object): def __init__(self, sysArgs): try: self.function = None self.args = [] self.modulePath = sysArgs[0] self.moduleDir, tail = os.path.split(self.modulePath) self.moduleName, ext = os

why args.add_argument works when given in two separate statements but not one in python?

穿精又带淫゛_ 提交于 2019-12-22 08:38:46
问题 I am trying to use argparse module to parse the arguments in command line. here is the sample code import argparse parser = argparse.ArgumentParser() parser.add_argument('bar') parser.add_argument('-foo') args=parser.parse_args() print args running this python argparsing.py "hello" Namespace(bar='hello', foo=None) however, this does not work import argparse parser = argparse.ArgumentParser() parser.add_argument('bar','--foo') #parser.add_argument('-foo') args=parser.parse_args() print args

Share properties from separate commands/process

ぐ巨炮叔叔 提交于 2019-12-22 08:23:55
问题 Im providing command line tool with several command and sub commands, Im using cobra command line and I’ve two separate commands that first is prerequisit e to other e.g. the first command is preferring the environment by creating temp folder and validate some file The second command should get some properties from the first command and user should execute it like btr prepare btr run when the run command is executed it should get some data from the prepare command outcome // rootCmd

How to access literal wildcard argument before it's expanded to matching files?

♀尐吖头ヾ 提交于 2019-12-22 08:22:50
问题 Background: I'm writing a bash script that must receive these arguments: a file name (a file containing a set of rules ) a list of file names ( files to be processed, can use wildcards) a destination folder ( where processed versions of files will be stored ) In theory there are 3 parameters but in reality the second argument expands, so the real number of argument varies if the wildcard matches more than one file: When I call ./myscript file.conf *.data dest_foder *.data expands into as many

Chrome's --auto-open-devtools-for-tabs

浪尽此生 提交于 2019-12-22 04:55:18
问题 I'm trying to get the devtools to open automatically when starting chrome from a shortcut with a command line switch --auto-open-devtools-for-tabs . i.e. the path of that shortcut is: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -incognito -auto-open-devtools-for-tabs (or --auto-open-devtools-for-tabs). But both don't seem to open the dev tools, neither does entering in the cmd chrome.exe -auto-open-devtools-for-tabs (or --auto-open-devtools-for-tabs), of course when in

Why isn't main defined `main(std::vector<std::string> args)`?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 01:56:10
问题 This question is only half tongue-in-cheek. I sometimes dream of a world without naked arrays or c strings. If you're using c++, shouldn't the preferred definition of main be something like: int main(std::vector<std::string> args) ? There are already multiple definitions of main to choose from, why isn't there a version that is in the spirit of C++? 回答1: A concern that keeps coming back to my mind is that once you allow complex types, you end up with the risk of exceptions being thrown in the

Why main() in C++ is not overloaded to use std::string?

雨燕双飞 提交于 2019-12-22 01:24:43
问题 I was trying to create a program that takes arguments by command line, using main() function arguments. As a (basic) C++ programmer (even if I know quite well pointers and array in C-style) I hardly ever used char* strings and C-arrays. I spent some to take main() arguments and transform it in std::string ... So asked myself: why in C++ the main() function is not overloaded to take an std::vector<std::string> argv instead of the old char* argv[] ? For "overload" I mean the coexistence of main

What JDBC property corresponds to mysql command line's “--skip-secure-auth” option?

可紊 提交于 2019-12-21 22:55:29
问题 I have one legacy database which needs to be connected like this from command prompt mysql --uUserName -hHostName -pPassword -P3307 -A Schema --skip-secure-auth How do I specify the same in JDBC properties --skip-secure-auth jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://HostName:3307/Schema jdbc.user=UserName jdbc.password=Password jdbc.maxConnections=5 回答1: --skip-secure-auth allows the use of the old, pre-4.1 password hashing method. This obsolete authentication mechanism is

Pass a variable number of bash command line arguments to a MATLAB function

守給你的承諾、 提交于 2019-12-21 20:25:05
问题 Arguments that are passed to a bash script can be passed on to a MATLAB function in the following way: #!/bin/bash matlab -nodesktop -nosplash -nodisplay -r "my_function('$1','$2')" But how to do this if I do not know the number of arguments to pass a priori? So I want to do something like this: #!/bin/bash matlab -nodesktop -nosplash -nodisplay -r "my_function('$1',...,'$N')" where I do not know what number N equals to a priori. I figure that you could create a string with a for loop

Passing a tuple as command line argument [duplicate]

为君一笑 提交于 2019-12-21 07:55:14
问题 This question already has answers here : converting string to tuple (3 answers) Closed 4 years ago . My requirement is to pass a tuple as command line argument like --data (1,2,3,4) I tried to use the argparse module, but if I pass like this it is receiving as the string '(1,2,3,4)' . I tried by giving type=tuple for argparse.add_argument , but is of no use here. Do I have to add a new type class and pass that to type argument of add_argument ? Update I tried the ast.literal_eval based on