command-line-arguments

Without access to argv[0], how do I get the program name?

对着背影说爱祢 提交于 2021-02-06 10:12:37
问题 I know the program name is passed as the first argument, and next simple example will print it to the standard output : #include <iostream> int main ( int argc, char *argv[] ) { std::cout<<argv[0]<<std::endl; } Is there a function to get the program name? EDIT I am starting the program from the shell, and the above code will always print the program name (I am using fedora 9, but I am sure it works in other distros). I have found that /proc/self/ directory might contain what I am looking for,

mkdir's “-p” option

隐身守侯 提交于 2021-02-05 12:39:15
问题 So this doesn't seem like a terribly complicated question I have, but it's one I can't find the answer to. I'm confused about what the -p option does in Unix. I used it for a lab assignment while creating a subdirectory and then another subdirectory within that one. It looked like this: mkdir -p cmps012m/lab1 This is in a private directory with normal rights ( rlidwka ). Oh, and would someone mind giving a little explanation of what rlidwka means? I'm not a total noob to Unix, but I'm not

How to identify what is causing the Segmentation fault

两盒软妹~` 提交于 2021-02-05 09:42:44
问题 My code's aim is to take in 2 command line arguments (inclusive of programme name), and to print out responses as shown based on the given 2nd command line argument. If the command line argument is an integer, the user's input is accepted or "Success"and if it as anything else (e.g. a string or more than one command line argument), it will be Null and the error message will be shown. This is for CS50 caesar for those who are familiar My Code is as follows: #include <stdio.h> #include <cs50.h>

How to identify what is causing the Segmentation fault

强颜欢笑 提交于 2021-02-05 09:42:30
问题 My code's aim is to take in 2 command line arguments (inclusive of programme name), and to print out responses as shown based on the given 2nd command line argument. If the command line argument is an integer, the user's input is accepted or "Success"and if it as anything else (e.g. a string or more than one command line argument), it will be Null and the error message will be shown. This is for CS50 caesar for those who are familiar My Code is as follows: #include <stdio.h> #include <cs50.h>

Implementing getarg subroutine call

China☆狼群 提交于 2021-02-04 21:44:11
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

落爺英雄遲暮 提交于 2021-02-04 21:43:46
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

霸气de小男生 提交于 2021-02-04 21:42:43
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Passing a url as argument

爷,独闯天下 提交于 2021-02-04 20:49:49
问题 Whenever I try to run the script as below, I get the following results. What is wrong with the code? 1. python test.py doesn't print the usage. 2. python test.py http://link.com/index.php?title=tesst&action=raw prints: "'action' is not recognized as an internal or external command, operable program or batch file." My script: # Version YYYYMMDD version = "20121112" # File type to be output to logs # Should be changed to exe before building the exe. fileType = "py" # Import sys to read command

Python argparse: default argument stored as string, not list

若如初见. 提交于 2021-02-04 14:32:11
问题 I cannot figure out this behaviour of argparse from the documentation: import argparse parser.add_argument("--host", metavar="", dest="host", nargs=1, default="localhost", help="Name of host for database. Default is 'localhost'.") args = parser.parse_args() print(args) Here is the output with and without an argument for "--host": >> python demo.py Namespace(host='localhost') >> python demo.py --host host Namespace(host=['host']) In particular: why does the argument to "--host" get stored in a

Argparse: nested optional argument, force --arg=val over --arg val, single occurrence, optional argument order

本秂侑毒 提交于 2021-01-29 09:21:58
问题 The program should be executed as follows: ./interpret.py --help | --source=FILE1 [--stats=FILE2 [--vars] [--insts]] the rules are: --help has to be the only argument if passed --source=FILE1 has to be provided and can't be passed like --source FILE1 if --vars or --insts is provided, then --stats=FILE2 has to be provided the order of --vars and --insts matters, therefore has to be stored multiple occurrence of an argument is forbidden I have read multiple tutorials and SO answers, but they