argv

Ruby's ARGV can be empty on windows depending on a way to run script

六眼飞鱼酱① 提交于 2019-12-01 02:12:17
问题 My demo.rb: puts ARGV.size ARGV.each do |a| puts "Argument: #{a}" end The result depends on how we run a script: > demo.rb foo bar 0 > ruby demo.rb foo bar 2 Argument: foo Argument: bar Why this happens? And can some thing be done with this? EDIT: Thanks to all replies! Here my settings: >assoc .rb .rb=rbFile >ftype rbFile rbFile="c:\ruby-1.8.6\bin\ruby.exe" "%1" %* So it looks right. But I have discovered that >demo.rb foo bar starts process with such Command Line: "C:\ruby-1.8.7\bin\ruby

Too many values to unpack

。_饼干妹妹 提交于 2019-12-01 01:35:44
I'm reading learn python the hard way, and on chapter 15 I'm suppose to use import argv to assign variables and raw input to gain user input. The script is: from sys import argv script, filename, = argv txt = open(filename) print " Here's your file %r :" % filename print txt.read() print " I'll also ask you to type it again: " file_again = raw_input ("> ") txt_again = open (file_again) print txt_again.read () After running this script I get the error, too many values to unpack. File "ex15.py", line 3, in script , filename = argv Value error: too many values to unpack Just a couple of pointers.

executing a process with argc=0

别来无恙 提交于 2019-11-30 23:45:08
问题 Is it possible to execute a process whose argc = 0? I need to execute a program but it is extremely important for its argc to be equal to 0. Is there a way to do that? I tried to put 2^32 arguments in the command line so that it appears as if argc = 0 but there is a maximum limit to the number of arguments. 回答1: You can write a program that calls exec directly; that allows you to specify the command-line arguments (including the program name) and lack thereof. 回答2: You may use linux system

How to use python argparse with args other than sys.argv?

大兔子大兔子 提交于 2019-11-30 22:07:01
问题 I've been all over the documentation and it seems like there's no way to do it, but: Is there a way to use argparse with any list of strings, instead of only with sys.argv? Here's my problem: I have a program which looks something like this: # This file is program1.py import argparse def main(argv): parser = argparse.ArgumentParser() # Do some argument parsing if __name__ == '__main__': main(sys.argv) This works fine when this program is called straight from the command line. However, I have

Argv - String into Integer

被刻印的时光 ゝ 提交于 2019-11-30 19:18:34
I'm pretty new at python and I've been playing with argv. I wrote this simple program here and getting an error that says : TypeError: %d format: a number is required, not str from sys import argv file_name, num1, num2 = argv int(argv[1]) int(argv[2]) def addfunc(num1, num2): print "This function adds %d and %d" % (num1, num2) return num1 + num2 addsum = addfunc(num1, num2) print "The final sum of addfunc is: " + str(addsum) When I run filename.py 2 2, does argv put 2 2 into strings? If so, how do I convert these into integers? Thanks for your help. sys.argv is indeed a list of strings. Use

How do I set the command line arguments in a C program so that it's visible when users type “ps aux”?

血红的双手。 提交于 2019-11-30 15:57:46
问题 When you type "ps aux" the ps command shows command arguments that the program was run with. Some programs change this as a way of indicating status. I've tried changing argv[] fields and it doesn't seem to work. Is there a standard way to set the command line arguments so that they appear when the user types ps? That is, this doesn't work: int main(int argc,char **argv) { argv[0] = "Hi Mom!"; sleep(100); } 09:40 imac3:~$ ./x & [2] 96087 09:40 imac3:~$ ps uxp 96087 USER PID %CPU %MEM VSZ RSS

How do I set the command line arguments in a C program so that it's visible when users type “ps aux”?

孤街浪徒 提交于 2019-11-30 15:07:41
When you type "ps aux" the ps command shows command arguments that the program was run with. Some programs change this as a way of indicating status. I've tried changing argv[] fields and it doesn't seem to work. Is there a standard way to set the command line arguments so that they appear when the user types ps? That is, this doesn't work: int main(int argc,char **argv) { argv[0] = "Hi Mom!"; sleep(100); } 09:40 imac3:~$ ./x & [2] 96087 09:40 imac3:~$ ps uxp 96087 USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND yv32 96087 0.0 0.0 2426560 324 s001 S 9:40AM 0:00.00 ./x 09:40 imac3:~$

Why does MPI_Init accept pointers to argc and argv?

隐身守侯 提交于 2019-11-30 10:59:40
this is how we use MPI_Init function int main(int argc, char **argv) { MPI_Init(&argc, &argv); … } why does MPI_Init use pointers to argc and argv instead of values of argv? NickTee According to the answer stated here: Passing arguments via command line with MPI Most MPI implementations will remove all the mpirun-related arguments in this function so that, after calling it, you can address command line arguments as though it were a normal (non-mpirun) command execution. i.e. after mpirun -np 10 myapp myparam1 myparam2 argc = 7(?) because of the mpirun parameters (it also seems to add some) and

Strange behavior of argv when passing string containing “!!!!”

本秂侑毒 提交于 2019-11-30 08:07:50
I have written a small program that takes some input parameters from *argv[] and prints them. In almost all use cases my code works perfectly fine. A problem only arises when I use more than one exclamation mark at the end of the string I want to pass as an argument ... This works: ./program -m "Hello, world!" This does NOT work: ./program -m "Hello, world!!!!" ^^ If I do this, the program output is either twice that string, or the command I entered previous to ./program. However, what I absolutely don't understand: The following, oddly enough, DOES work: ./program -m 'Hello, world!!!!' ^^ The

Using getopt in C with non-option arguments

天大地大妈咪最大 提交于 2019-11-30 06:52:53
I'm making a small program in C that deals with a lot of command line arguments, so I decided to use getopt to sort them for me. However, I want two non-option arguments (source and destination files) to be mandatory, so you have to have them as arguments while calling the program, even if there's no flags or other arguments. Here's a simplified version of what I have to handle the arguments with flags: while ((c = getopt(argc, argv, "i:d:btw:h:s:")) != -1) { switch (c) { case 'i': { i = (int)atol(optarg); } case 'd': { d = (int)atol(optarg); } case 'b': buf = 1; break; case 't': time = 1;