argv

perl how to pass argument to ARGV from a text file

I have a list of arguments to pass into a perl script, using ARGV. The 4th argument, is a servername, but I want to pass it a text file with a list of servers called servers.txt. How do I pass that in and use it as an argument to ARGV? Sample file 'servers.txt': server1 server2 server3 Working code: # usage example: ./test.pl Jul 05...

Pass application via argv in Applescript

I would like to pass the name of an application to an applescript and then perform some actions on it in the script. I've tried the following: set app_name to item 1 of argv tell application app_name to ... This doesn't work. I've tried set app_name to quoted form of item 1 of argv which seems to append single quotes, (doesn't work...

Why hex in string is not converted to hex when passed through command line argument?

What I understand that hexadecimal numbers can be placed into string using \x. For example 0x41 0x42 can be placed in string as "\x41\x42". char * ptr = "\x41\x42" ; printf( "%s\n" , ptr ) // AB \x is discarded and 41 is considered as a hex by the compiler. But if I pass it to my program through command line arguments, it does not wo...

How do I sort the elements of argv in C?

I am trying to alphabetically sort the elements of argv. The following line of code is giving me problems: qsort(argv[optind], argc - optind, sizeof(argv[optind]), sort); Specifically, the last argument is giving me trouble, the comparison function, which is given below: int sort(const void *a, const void * b) { return(st...

argv[argc] == ?

My professor and a couple of students are arguing about if argv is null terminated or not. My friend wrote a small program and it printed out null but another kid is saying that he is probably just reading into blank memory. Can someone solve this discussion? -Jake ...

How to get the name of the input file in a Perl one-liner?

cat monday.csv 223.22;1256.4 227.08;1244.8 228.08;1244.7 229.13;1255.0 227.89;1243.2 224.77;1277.8 cat tuesday.csv 227.02;1266.3 227.09;1234.9 225.18;1244.7 224.13;1255.3 228.59;1263.2 224.70;1247.6 This Perl one-liner gives me the row with the highest value in the second column from the rows where in...

can you flag command line inputs in python?

a lot of command-line .exe applications i use allow you flag optional inputs e.g. program.exe -o outputfile.txt -f F where "-o" indicates an optional output file name different to the default, and where "-F' indicates another option about the script. so far i've been using the sys.arg[] variables to input file names and such to my pyth...

Python: in what encoding is sys.argv?

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...

How can I tell a Perl function that takes a file to read from the special ARGV handle?

In perldoc perlvar, I read this: Note that currently "ARGV" only has its magical effect within the "<>" operator; elsewhere it is just a plain filehandle corresponding to the last file opened by "<>". In particular, passing "*ARGV" as a parameter to a function that expects a filehandle may not cause your function to a...

How to access argv[] from outside the main() function?

Hello, I happen to have several functions which access different arguments of the program through the argv[] array. Right now, those functions are nested inside the main() function because of a language extension the compiler provides to allow such structures. I would like to get rid of the nested functions so that interoperability is p...