argv

int main(int argc, char *argv[])

此生再无相见时 提交于 2019-11-28 01:23:07
问题 If I have this: int main(int argc, char *argv[]) In the body, you can sometimes find programs using argv[1] . When do we use argv[1] over argv[0] ? Is it only when we just want to read the second argument in the command line? 回答1: By convention , argv[0] is the current program's name (or path), and argv[1] through argv[argc - 1] are the command-line arguments that the user provides. However, this doesn't have to be true -- programs can OS-specific functions to bypass this requirement, and

Is argv[argc] equal to NULL Pointer [duplicate]

有些话、适合烂在心里 提交于 2019-11-27 23:55:06
问题 This question already has an answer here: argv[argc] ==? 2 answers I read an article (forgot the URL), which said that argv[argc] is a NULL pointer (contains \0 ). To check whether if its true I wrote this code, yeah it exist. What I don't understand is, why does the OS include this NULL pointer at argv[argc] . Is it useful for something else also? int main (int argc, char **argv){ while (*argv) printf ("%s\n", *argv++); return 0; } 回答1: The C Standard 5.1.2.2.1/2 second mark says explicitly

How to print argv[0] in NASM?

给你一囗甜甜゛ 提交于 2019-11-27 22:36:45
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 push program call printf add esp, 8 push 0 call exit Specs: ld 64-134.9 nasm 0.98.40 Xcode 4.5 Mac OS X

Change process name without changing argv[0] in Linux

家住魔仙堡 提交于 2019-11-27 20:51:14
I need to modify the process name of my program in C language. I precise, this is not the name of a thread that I want to change. I want to change the name of my program, but the only solution I found, is to modify the value of argv[0] . I also found another solution with prctl(PR_SET_NAME, "newname") , but this solution doesn't work. Wayne The differences between invoking prctl and modify argv[0] are: modify argv[0] changes information in /proc/$pid/cmdline invoking prctl(PR_SET_NAME) changes information in /proc/$pid/status That means you will get difference name of your process issuing ps

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

China☆狼群 提交于 2019-11-27 16:31:10
问题 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 def suite(self): modules_to_test = ('external_sanity_onvif', 'starttest') alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases

Using argv in C?

自作多情 提交于 2019-11-27 16:09:44
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(argv[1]=="-e"){ // Do some stuff with argv[2] system("PAUSE"); } else{ printf("Error: Incorrect usage - first argument must be -e"); return 0; } } So I am calling my program as "program.exe -e myargstuff" but I am getting the "Error: Incorrect Usage..." output, even though my

How to find the length of argv[] in C

坚强是说给别人听的谎言 提交于 2019-11-27 15:57:10
问题 #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]){ int fir; //badly named loop variable char *input[] = calloc( strlen(argv), sizeof(char)); //initializing an array for( fir = 1; fir< strlen(argv); fir++){ //removing the first element of argv strcat(input, argv[fir]); // appending to input } } The error I'm getting is for line 7. It says "passing argument 1 of 'strlen' from incompatible pointer type". I get the same error for the strcat function. It

Retrieve the command line arguments of the Python interpreter

…衆ロ難τιáo~ 提交于 2019-11-27 15:52:12
问题 Inspired by another question here, I would like to retrieve the Python interpreter's full command line in a portable way. That is, I want to get the original argv of the interpreter, not the sys.argv which excludes options to the interpreter itself (like -m , -O , etc.). sys.flags tells us which boolean options were set, but it doesn't tell us about -m arguments, and the set of flags is bound to change over time, creating a maintenance burden. On Linux you can use procfs to retrieve the

Get other process' argv in OS X using C

六眼飞鱼酱① 提交于 2019-11-27 05:22:21
I want to get other process' argv like ps. I'm using Mac OS X 10.4.11 running on Intel or PowerPC. First, I read code of ps and man kvm, then I wrote some C code. #include <kvm.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/sysctl.h> #include <paths.h> int main(void) { char errbuf[1024]; kvm_t *kd = kvm_openfiles(_PATH_DEVNULL, NULL, _PATH_DEVNULL, O_RDONLY, errbuf); int num_procs; if (!kd) { fprintf(stderr, "kvm_openfiles failed : %s\n", errbuf); return 0; } struct kinfo_proc *proc_table = kvm_getprocs(kd, KERN_PROC_ALL, 0, &num_procs); for (int i = 0; i < num

Difference between char *argv[] and char **argv for the second argument to main()

。_饼干妹妹 提交于 2019-11-27 05:15:20
问题 CODE 1 #include<stdio.h> int main(int argc, char *argv[]) { int j; printf("%d", argv[1][0]); return 0; } CODE 2 #include<stdio.h> int main(int argc, char **argv) { int j; printf("%d", argv[1][0]); return 0; } CODE 1 and CODE 2 both give same output. but argument 2 of main function in CODE 1 and CODE 2 are different. Array of pointers are created above data section at compile time. argv is array of pointers. Then we should declare argument in main function as pointer to pointer to character i