argv

argv[argc] ==?

时光怂恿深爱的人放手 提交于 2019-11-26 20:39:57
My professor and a couple of students are arguing about whether argv is null terminated or not. My friend wrote a small program and it printed out null but another kid said that he is probably simply reading into blank memory. Can someone solve this discussion? From the Standard: 5.1.2.2.1 Program startup ... -- argv[argc] shall be a null pointer. So, yes; argv is null terminated According to the standard, "argv[argc] shall be a null pointer" (5.1.2.2.1). 来源: https://stackoverflow.com/questions/3772796/argvargc

how to change the name of a Java application process?

对着背影说爱祢 提交于 2019-11-26 16:16:18
When executing a Java application the process name given to it is usually java.exe or javaw.exe . But how can I make it be called by the name of my application? KarlP These methods are suited for servers with a lot of java processes running, and where you need a quick way of finding the correct jvm (not using jps.) For applications, I suppose launch4j or another wrapper is the way to go. On unix, If you are launching from a shell sript (at least for bash and possibly for other decent shells) you can use: exec -a goodname java ... to launch java and pass "goodname" as the 0th argument, which

Get other process' argv in OS X using C

Deadly 提交于 2019-11-26 11:34:10
问题 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; }

How to access command line arguments of the caller inside a function?

不打扰是莪最后的温柔 提交于 2019-11-26 10:36:40
问题 I\'m attempting to write a function in bash that will access the scripts command line arguments, but they are replaced with the positional arguments to the function. Is there any way for the function to access the command line arguments if they aren\'t passed in explicitly? # Demo function function stuff { echo $0 $* } # Echo\'s the name of the script, but no command line arguments stuff # Echo\'s everything I want, but trying to avoid stuff $* 回答1: My reading of the bash ref manual says this

argv[argc] ==?

。_饼干妹妹 提交于 2019-11-26 09:46:34
问题 My professor and a couple of students are arguing about whether argv is null terminated or not. My friend wrote a small program and it printed out null but another kid said that he is probably simply reading into blank memory. Can someone solve this discussion? 回答1: From the Standard: 5.1.2.2.1 Program startup ... -- argv[argc] shall be a null pointer. So, yes; argv is null terminated 回答2: According to the standard, "argv[argc] shall be a null pointer" (5.1.2.2.1). 来源: https://stackoverflow

An integer is required? open()

佐手、 提交于 2019-11-26 09:38:54
问题 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 = line.split(\'=\') t[1].strip(\'\\\'\') vals.append(t[0], t[1]) print vals f.close() when i try to run it i get: Traceback (most recent call last): File \"chval

When can argv[0] have null?

做~自己de王妃 提交于 2019-11-26 09:34:48
问题 What I have understand about passing arguments to main() from command line is that argc has a minimum value of 1 and argv[0] will always have the program name with its path in it. If arguments are provided at the command line, then argc will have a value greater than one and argv1 to argv[argc-1] will have those arguments. Now a paragraph at this link says that argv[0] will be a string containing the program\'s name or a null string if that is not available. Now, how and when can argv[0] have

Regarding &#39;main(int argc, char *argv[])&#39; [duplicate]

白昼怎懂夜的黑 提交于 2019-11-26 08:40:05
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: What are the arguments to main() for? What does int argc, char *argv[] mean? Every program is starting with the main(int argc, char *argv[]) definition. I don\'t understand what it means. I would be very glad if somebody could explain why we use these arguments if we don\'t use them in the program? Why not just: int main() ? Is the name of the program one of the elements of *argv[] and argc is the count of the

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

江枫思渺然 提交于 2019-11-26 01:35:59
问题 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? 回答1: Guesswork (even educated guesswork) is fun but you really need to go to the standards documents to be sure. For example, ISO C11 states (my emphasis): If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if

What does int argc, char *argv[] mean?

你说的曾经没有我的故事 提交于 2019-11-25 22:16:21
问题 In many C++ IDE\'s and compilers, when it generates the main function for you, it looks like this: int main(int argc, char *argv[]) When I code C++ without an IDE, just with a command line compiler, I type: int main() without any parameters. What does this mean, and is it vital to my program? 回答1: argv and argc are how command line arguments are passed to main() in C and C++. argc will be the number of strings pointed to by argv . This will (in practice) be 1 plus the number of arguments, as