argv

Numbers passed as command line arguments in python not interpreted as integers

帅比萌擦擦* 提交于 2019-11-27 03:46:34
问题 I am familiar with C, and have started experimenting in python. My question is regarding the sys.argv command. I've read it is used for a command line interpreter, but when trying to execute a simple program I don't get the results I expect. Code: import sys a = sys.argv[1] b = sys.argv[2] print a, b print a+b Input: python mySum.py 100 200 Output: 100 200 100200 When I add the two arguments they are concatenated instead of the two values being added together. It seems that the values are

How to access command line arguments of the caller inside a function?

核能气质少年 提交于 2019-11-27 03:35:15
I'm attempting to write a function in bash that will access the scripts command line arguments, but they are replaced with the positional arguments to the function. Is there any way for the function to access the command line arguments if they aren't passed in explicitly? # Demo function function stuff { echo $0 $* } # Echo's the name of the script, but no command line arguments stuff # Echo's everything I want, but trying to avoid stuff $* mcarifio My reading of the bash ref manual says this stuff is captured in BASH_ARGV, although it talks about "the stack" a lot. #!/bin/bash function argv {

Are char * argv[] arguments in main null terminated?

℡╲_俬逩灬. 提交于 2019-11-27 03:01:41
问题 So I'm wondering if command line parameters are always null terminated? Google seems to say yes, and compiling on GCC indicates this is the case, but can I guarantee this to always be true? int main(int argc, char** argv) { char *p; for(int cnt=1; cnt < argc; ++cnt) { p = argv[cnt]; printf("%d = [%s]\n", cnt, p); } return 0; } $ MyProgram -arg1 -arg2 -arg3 1 = -arg1 2 = -arg2 3 = -arg3 回答1: Yes. The non-null pointers in the argv array point to C strings, which are by definition null

Python: Which encoding is used for processing sys.argv?

我们两清 提交于 2019-11-27 02:05:51
问题 In what encoding are the elements of sys.argv , in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS : As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess . I would love to see a definitive answer to this question, though, with pointers to solid sources! PPS : As Wim pointed out, Python 3 solves this issue by putting

What does 'sys.argv' mean?

放肆的年华 提交于 2019-11-27 02:05:43
问题 I am learning from code, and I am get confused by one of its lines which is: things = [float(arg) for arg in sys.argv[1:]] Omega_a, Omega_b, Delta_a, Delta_b, \ init_pop_a, init_pop_b, tstep, tfinal = things I have searched online and tried to understand what sys.arg means, and here is my understanding: So sys.argv[0] is the file name, and sys.argv[1:] is the rest of the parameters which should given by users. I am not sure am I understood it right, and if it is, then I don't understand why

How to change argv0 in bash so command shows up with different name in ps?

懵懂的女人 提交于 2019-11-27 01:39:00
问题 In a C program I can write argv[0] and the new name shows up in a ps listing. How can I do this in bash? 回答1: You can do it when running a new program via exec -a <newname> . 回答2: Just for the record, even though it does not exactly answer the original poster's question, this is something trivial to do with zsh : ARGV0=emacs nethack 回答3: I've had a chance to go through the source for bash and it does not look like there is any support for writing to argv[0]. 回答4: I'm assuming you've got a

When can argv[0] have null?

泪湿孤枕 提交于 2019-11-27 01:07:57
What I have understand about passing arguments to main() from command line is that argc has a minimum value of 1 and argv[0] will always have the program name with its path in it. If arguments are provided at the command line, then argc will have a value greater than one and argv 1 to argv[argc-1] will have those arguments. Now a paragraph at this link says that argv[0] will be a string containing the program's name or a null string if that is not available. Now, how and when can argv[0] have null string? I mean program name with its path will always be available so when can it be null? Writer

Regarding 'main(int argc, char *argv[])' [duplicate]

五迷三道 提交于 2019-11-26 23:27:32
Possible Duplicates: What are the arguments to main() for? What does int argc, char *argv[] mean? Every program is starting with the main(int argc, char *argv[]) definition. I don't understand what it means. I would be very glad if somebody could explain why we use these arguments if we don't use them in the program? Why not just: int main() ? Is the name of the program one of the elements of *argv[] and argc is the count of the number of arguments in *argv[] ? What are the other arguments sent to *argv[] ? How do we send them? Frank The arguments argc and argv of main is used as a way to send

What's the point of ARGV in Ruby?

≡放荡痞女 提交于 2019-11-26 23:11:43
问题 What's the point of ARGV in Ruby? first, second, third = ARGV puts "The script is called: #{$0}" puts "Your first variable is: #{first}" puts "Your second variable is: #{second}" puts "Your third variable is: #{third}" What's the point of this when to run the file I need to do: ruby ex1.rb and to put in the first, second and third variables I need to type in ruby ex1.rb blah blah blah How does this benefit at all the person running the program? They can't do it anyway since I'd assume it be

How to print argv[0] in NASM?

馋奶兔 提交于 2019-11-26 21:04:25
问题 I want to store argv[0] in a register and then print it, but I'm getting a segfault when I run my assembly program. Trace: $ nasm -f macho -o scriptname.o --prefix _ scriptname.asm $ ld -o scriptname scriptname.o -arch i386 -lc -macosx_version_min 10.6 -e _start -no_pie $ ./scriptname Segmentation fault: 11 scriptname.asm: [bits 32] section .data program: db "Program: %s", 0 section .text global start extern printf extern exit start: ; skip argc add esp, 4 ; ebx := argv[0] pop ebx push ebx