argv

How to Get the Path of the executing frozen script

折月煮酒 提交于 2019-12-04 20:19:48
问题 If you are running a frozen python script (frozen using py2exe) from a directory and drive different from where the script is present, what is the best way to determine the path of the executing script? Few solutions I have tried inspect.getfile(inspect.currentframe()) Problem: Does not return the full path. It only returns the script name. os.path.abspath( __file__ ) Problem: Doesn't work on Windows os.path.dirname(sys.argv[0]) Problem: Returns empty string. os.path.abspath(inspect

Char isn't converting to int

随声附和 提交于 2019-12-04 18:17:40
问题 For some reason my C program is refusing to convert elements of argv into ints, and I can't figure out why. int main(int argc, char *argv[]) { fprintf(stdout, "%s\n", argv[1]); //Make conversions to int int bufferquesize = (int)argv[1] - '0'; fprintf(stdout, "%d\n", bufferquesize); } And this is the output when running ./test 50: 50 -1076276207 I have tried removing the (int), throwing both a * and an & between (int) and argv[1] - the former gave me a 5 but not 50, but the latter gave me an

How to call correctly getopt function

 ̄綄美尐妖づ 提交于 2019-12-04 13:22:17
Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17 `check.cpp: In function ‘int main()’:` check.cpp:14:55: error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive] /usr/include/getopt.h:152:12: error: initializing argument 2 of ‘int getopt(int, char* const*, const char*)’ [-fpermissive] #include <iostream> #include <cstring> #include <string> #ifdef USE_UNISTD #include <unistd.h> #else #include "XGetopt.h" #endif using namespace std; int main() { string text="-f input.gmn -output.jpg"; int argc=text

Jython 2.5.1: Calling From Java into __main__ - how to pass in command line args?

岁酱吖の 提交于 2019-12-04 11:15:53
I'm using Jython from within Java; so I have a Java setup similar to below: String scriptname="com/blah/myscript.py" PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); InputStream is = this.getClass().getClassLoader().getResourceAsStream(scriptname); interpreter.execfile(is); And this will (for instance) run the script below: # myscript.py: import sys if __name__=="__main__": print "hello" print sys.argv How I pass in 'commandline' arguments using this method ? (I want to be able to write my Jython scripts so that I can also run them on the commandline with

Why call sscanf() with argv[] can only use once?

假如想象 提交于 2019-12-04 06:04:13
问题 I need to get argv[1] and argv[2] to different types. I found that I could only use sscanf() once or the next string in argv cannot be retrieved. Here's my code. int main( int argc, char *argv[]) { char t; float temp; sscanf(argv[1], "-%[cf]",&t); sscanf(argv[2], "%f", &temp); return 0; } Only the first sscanf() can get the formatted value. How could I also get done with argv[2]? 回答1: Attempt to save string data in a char leading to undefined behavior (UB). "%[]" expects to match a character

Memory allocation and **argv argument [closed]

自作多情 提交于 2019-12-04 03:14:47
Closed . This question needs details or clarity. It is not currently accepting answers. Learn more . Want to improve this question? Add details and clarify the problem by editing this post . Closed 5 years ago . I know for what we use this argument, and I even know how to work with the argument. There is only one things I still do not understand. How a program allocate memory for strings which came from the input. **argv has no allocated memory at the start of the program, isn't it? I was expecting segfault, but it didn't happen. Does anybody know how this memory allocation work? The C/C++

Python Popen sending to process on stdin, receiving on stdout

*爱你&永不变心* 提交于 2019-12-04 02:36:47
I pass an executable on the command-line to my python script. I do some calculations and then I'd like to send the result of these calculations on STDIN to the executable. When it has finished I would like to get the executable's result back from STDOUT. ciphertext = str(hex(C1)) exe = popen([sys.argv[1]], stdout=PIPE, stdin=PIPE) result = exe.communicate(input=ciphertext)[0] print(result) When I print result I get nothing, not None, an empty line. I'm sure that the executable works with the data as I've repeated the same thing using the '>' on the command-line with the same previously

How to write own isnumber() function?

只谈情不闲聊 提交于 2019-12-03 18:08:06
问题 I'm new to C and I'm thinking how to write this function myself. I take a parameter from command line, so it is stored in argv array and I want to decide whether it is or isn't number. What is the easiest way to do this? Thank you #include <stdio.h> int isNumber(int *param) { if (*param > 0 && *param < 128) return 1; return 0; } int main(int argc, char *argv[]) { if (argc == 2) isNumber(argv[1]); else printf("Not enought parameters."); return 0; } 回答1: Read about strtol(3). You could use it

Using argc and argv in Eclipse?

馋奶兔 提交于 2019-12-03 14:41:09
I have a working program but now I have to use the int argc and char *argv[] parameters to main . Whenever I try to do this it gives me errors that it cannot save. Is there any way to make argc and argv work in Eclipse? I guess your problem is that you don't know hot to pass argument to you program, when you execute it through eclipse isn't it ? If that is what you want, read the following. Click on the "Project->Properties" then in "Run/Debug settings" click on the "New button". Choose C++ application. Here you can see that there are 4 tabs, and the second tab is called "arguments". In this

How to Get the Path of the executing frozen script

微笑、不失礼 提交于 2019-12-03 12:33:56
If you are running a frozen python script (frozen using py2exe) from a directory and drive different from where the script is present, what is the best way to determine the path of the executing script? Few solutions I have tried inspect.getfile(inspect.currentframe()) Problem: Does not return the full path. It only returns the script name. os.path.abspath( __file__ ) Problem: Doesn't work on Windows os.path.dirname(sys.argv[0]) Problem: Returns empty string. os.path.abspath(inspect.getsourcefile(way3)) Will not work if the drive is different from the pwd os.path.dirname(os.path.realpath(sys