argv

Python, how to parse strings to look like sys.argv

I would like to parse a string like this: -o 1 --long "Some long string" into this: ["-o", "1", "--long", 'Some long string'] or similar. This is different than either getopt, or optparse, which start with sys.argv parsed input (like the output I have above). Is there a standard way to do this? Basically, this is "splitting" wh...

An integer is required? open()

I have a very simple python script that should scan a text file, which contains lines formatted as id='value' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code: import os,sys from os import * from sys import * vals = {} f = open(sys.argv[1], 'r') for line in val_f: t = li...

Visual C++ argv question

I'm having some trouble with Visual Studio 2008. Very simple program: printing strings that are sent in as arguments. Why does this: #include <iostream> using namespace std; int _tmain(int argc, char* argv[]) { for (int c = 0; c < argc; c++) { cout << argv[c] << " "; } } For these arguments: program.exe testing on...

How do I handle argv character array assignments?

I found two ways of passing command-line arguments into a character array: int main (int argc, char **argv) { const char *s1 = argv[0]; char s2[256]; strcpy(s2, argv[0]); printf("s1: %s\ns2: %s\n\n", s1, s2); } Compiled with the IBM xlc compiler on an AIX system Returns [MyPrompt]> ./a.out s1: ./a.out s2: ./a.o...

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

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

Can I skip a whole file with the <> operator?

The following Perl code has an obvious inefficiency; while (<>) { if ($ARGV =~ /\d+\.\d+\.\d+/) {next;} ... or do something useful } The code will step through every line of the file we don't want. On the size of files this particular script is running on this is unlikely to make a noticeable difference, but for the sake of learnin...

convert string to argv in c++

I have an std::string containing a command to be executed with execv, what is the best "C++" way to convert it to the "char *argv[]" that is required by the second parameter of execv()? To clarify: std::string cmd = "mycommand arg1 arg2"; char *cmd_argv[]; StrToArgv(cmd, cmd_argv); // how do I write this function? execv(cmd_argv[0], ...

Convert std::vector<char*> to a c-style argument vector arv

I would like to prepare an old-school argument vector (argv) to use within the function int execve(const char *filename, char *const argv[],char *const envp[]); I tried it with the stl::vector class: std::string arguments = std::string("arg1"); std::vector<char*> argv; char argument[128]; strcpy(argument, arguments.c_str()...

How to set mutiple words variable from command line input in C shell

I'm writing a script to search for a pattern in file. For example scriptname pattern file1 file2 filenN I use for loop to loop through arguments argv, and it does the job if all arguments are supplied. However if only one argument is supplied (in that case pattern ) it should ask to input file name or names, and then check for pattern....

Determine if string from argv[1] starts with a character or number (C-programming)

I'm writing a small application in C that takes two parameters. One is a filename, the other a number, and they may be specified in random order. ./main filename 12345 and ./main 12345 filename should both work. How can I easily determine which is which when I know the filename starts with a character? ...

Is "argv[0] = name-of-executable" an accepted standard or just a common convention?

When passing argument to main() in a C or C++ application, will argv[0] always be the name of the executable? Or is this just a common convention and not guaranteed to be true 100% of the time? ...

create array of pointers to files

How would I go about making an array of file pointers in C? I would like to create an array of file pointers to the arguments of main... like a1.txt, a2.txt, etc... So I would run ./prog arg1.txt arg2.txt arg3.txtto have the program use these files. Then the argument for main is char **argv From argv, I would like to create the array of...

Using argv in C?

For an assignment, I am required to have command line arguments for my C program. I've used argc/argv before (in C++) without trouble, but I'm unsure if C style strings are affecting how this works. Here is the start of my main: int main(int argc, char *argv[]){ if(argc>1){ printf("0 is %s, 1 is %s\n",argv[0],argv[1]); if(a...

I'm trying to run some PHP scripts as CLI instead of over HTTP. How do I make them play nice?

Hi everyone. I'm using some PHP scripts from FeedForAll to join together RSS feeds (RSSmesh) and display them as HTML (RSS2HTML). Because I intend to run these scripts fairly intensively and don't want the resulting HTTP requests and bandwidth to count towards my hosting quota, I am in the process of moving to running them on the web ho...

C++ argv path specifier

In the interpreter for my programming languages I have to correctly handle the parts in case the import function is called. I then need to check if such a file is in the /libs folder (located at the same place as my executeable!) and if it doesn't exist I have to check in the directory of the current script. How can I get the exact pat...

Why does MPI_Init accept pointers to argc and argv?

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

Problem with sys.argv[1] when unittest module is in a script

Hello, I have a script that does various things and access paramenters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value = sys.argv[1] def hello(self): print self.value ...

How do I launch a subprocess in C# with an argv? (Or convert agrv to a legal arg string)

I have a C# command-line application that I need to run in windows and under mono in unix. At some point I want to launch a subprocess given a set of arbitrary paramaters passed in via the command line. For instance: Usage: mycommandline [-args] -- [arbitrary program] Unfortunately, System.Diagnostics.ProcessStartInfo only takes a st...

How do I benefit from argc and argv in C++, the standard way?

What is the standard way to retrive and check for the argc and argv and what is the best usage and how to do that in linux? Please provide examples. "I want to have a complex command-line options and I want to use them in my application" That what I mean. Thanks ...

c++ - arguments to main

Hi! very basic question. i try to write a program that outputs the filenames of the files dragged onto the exe. i followed this guide for main arguments: http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html this is my code: #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR*...