Search Results

Search found 1221 results on 49 pages for 'argv'.

Page 1/49 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Building argv and argc

    - by Wylie Coyote SG.
    I'm a student programmer using Qt to build a GUI application for work. The primary purpose of this application is to open some of our old style files, allows better editing and then save the file in a new format and file extension. Recently I have been asked to allow this conversion to take place from a terminal. While I do know what argv and argc are along with what they represent I am unsure how to accomplish what they want. For instance how to handle relative paths vs. absolute... maybe how to get absolute from relative; perhaps none of that is even needed. My programming experience has been primarily with guis so this is a little new to me. Users would like the following to be ran from the terminal application -o /fileLocation /fileDestination template(to determine new format) I began to use for loops and if statements to begin accomplishing this when I relized that I might be taking the worng approach to all of this. I WOULD ALSO BE REALLY INTERESTED IF QT HAS SOMETHING FOR THIS! Here is what I have began coming up with: int main(int argc, char *argv[]) { if(argc > 1) { for(int i = 0; i < argc; i++) { if(argv[i] == "-c") { QString fileName = QString::fromStdString(argv[i+1]); QString fileDestination = QString::fromStdString(argv[i+2]); QString templateName = QString::fromStdString(argv[i+3]); QFile fileToConvert(fileName); if(fileToConvert.open(QFile::ReadOnly)) { //do stuff Thanks for reading my post and a big thanks for any contributions you make to helping me overcome this issue.

    Read the article

  • convert string to argv in c++

    - by aaronstacy
    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], cmd_argv);

    Read the article

  • C++ argv path specifier

    - by sub
    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 path to the directory where the executeable is located from argv? What is the best way to remove the file from the end of a path, e.g: C:/a/b/c/file.exe should become C:/a/b/c/

    Read the article

  • Storing and reading file paths from _TCHAR *argv[]

    - by ArsenArsen
    How to convert from _TCHAR* to "" and to keep all : and /? I tried: int _tmain(int argc, _TCHAR* argv[]) { if(!argv[1]){ std::cout<<"No Variables.\r\n"; system("PAUSE"); return 0; std::exit; } std::cout<<"Path: "<<argv[1]<<"\r\n"; system("PAUSE"); return 0; } But, output is either "No variables." or "Path: C" (when I changed _TCHAR to const char and char) or either "Path: 00038706"

    Read the article

  • Writing a basic C Shell - understanding argv[] [on hold]

    - by Flame
    I have an assignment for my class to write a basic C Shell. I have found many pages that explain parts of it and some fully implemented code. I'm not going to copy, i'm just using it right now as a way to get started. So I'm at the beginning of this project obviously. One example I am looking at parses the user's input and stores a pointer to the beginning of the argument in char *argv[3]; Am I just misunderstanding this or would this technically break if there are more than 3 arguments? (say /a.out arg1 arg2 arg3 etc). Would I wanna malloc this somehow? I know a.out is considered argv[0], and the arguments argv1 - however many there are. It's probably bad practice to have too many arguments for a program, but I still would at least want to address it as I don't know what my TA's are going to use to test my shell.

    Read the article

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

    - by lucas
    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 string for args. This is a problem for commands such as: ./my_commandline myarg1 myarg2 -- grep "a b c" foo.txt In this case argv looks like : argv = {"my_commandline", "myarg1", "myarg2", "--", "grep", "a b c", "foo.txt"} Note that the quotes around "a b c" are stripped by the shell so if I simply concatenate the arguments in order to create the arg string for ProcessStartInfo I get: args = "my_commandline myarg1 myarg2 -- grep a b c foo.txt" Which is not what I want. Is there a simple way to either pass an argv to subprocess launch under C# OR to convert an arbitrary argv into a string which is legal for windows and linux shell? Any help would be greatly appreciated.

    Read the article

  • Python: Which encoding is used for processing sys.argv?

    - by EOL
    What encoding are the elements of sys.argv in, in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS: As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess. I would love to see a definitive answer to this question, though, with pointers to solid sources! PPS: As Wim pointed out, Python 3 solves this issue by putting str objects in sys.argv (if I understand correctly). The question remains open for Python 2.x, though. Under Unix, the LC_CTYPE environment variable seems to be the correct thing to check, no? What should be done with Windows (so that sys.argv elements are correctly interpreted whatever the console)?

    Read the article

  • Python sys.argv lists and indexes

    - by Fred Gerbig
    In the below code I understand that sys.argv uses lists, however I am not clear on how the index's are used here. def main(): if len(sys.argv) >= 2: name = sys.argv[1] else: name = 'World' print 'Hello', name if __name__ == '__main__': main() If I change name = sys.argv[1] to name = sys.argv[0] and type something for an argument it returns: Hello C:\Documents and Settings\fred\My Documents\Downloads\google-python-exercises \google-python-exercises\hello.py Which kind of make sense. Can someone explain how the 2 is used here: if len(sys.argv) >= 2: And how the 1 is used here: name = sys.argv[1]

    Read the article

  • python - sys.argv and flag identification

    - by tekknolagi
    when I accept arguments how do I check if two show up at the same time without having a compound conditional i.e. #!/usr/bin/python import random, string import mymodule import sys z = ' '.join(sys.argv[2:]) q = ''.join(sys.argv[3:]) a = ''.join(sys.argv[2:]) s = ' '.join(sys.argv[1:]) flags = sys.argv[1:5] commands = [["-r", "reverse string passed next with no quotes needed."], ["-j", "joins arguments passed into string. no quotes needed."], ["--palindrome", "tests whether arguments passed are palindrome or not. collective."],["--rand","passes random string of 10 digits/letters"]] try: if "-r" in flags: if "-j" in flags: print mymodule.reverse(q) if not "-j" in flags: print mymodule.reverse(z) if "-j" in flags: if not "-r" in flags: print a if "--palindrome" in flags: mymodule.ispalindrome(z) if (not "-r" or not "-j" or not "--palindrome") in flags: mymodule.say(s) if "--rand" in flags: print(''.join([random.choice(string.ascii_letters+"123456789") for f in range(10)])) if not sys.argv[1]: print mymodule.no_arg_error if "--help" in flags: print commands except: print mymodule.no_arg_error i just want to be able to say if "-r" and "-j" in flags in no particular order: do whatever

    Read the article

  • Argc/Argv C Problems

    - by Salman
    Hey all, If I have the following code: main(int argc, char *argv[]){ char serveradd[20]; strcpy(serveradd, argv[1]); int port = atoi(argv[2]); printf("%s %d \n", serveradd, port); The first two arguments to the command line are printed. However, if I do this: char serveradd[20]; strcpy(serveradd, argv[1]); int port = atoi(argv[2]); char versionnum[1]; strcpy(versionnum, argv[3]); printf("%s %d %s \n", serveradd, port, versionnum);` The first argument (serveradd) does not print out to the screen and is not being stored... Why is this happening and how can I fix it? Thanks!

    Read the article

  • Jumping into argv?

    - by jth
    Hi, I`am experimenting with shellcode and stumbled upon the nop-slide technique. I wrote a little tool that takes buffer-size as a parameter and constructs a buffer like this: [ NOP | SC | RET ], with NOP taking half of the buffer, followed by the shellcode and the rest filled with the (guessed) return address. Its very similar to the tool aleph1 described in his famous paper. My vulnerable test-app is the same as in his paper: int main(int argc, char **argv) { char little_array[512]; if(argc>1) strcpy(little_array,argv[1]); return 0; } I tested it and well, it works: jth@insecure:~/no_nx_no_aslr$ ./victim $(./exploit 604 0) $ exit But honestly, I have no idea why. Okay, the saved eip was overwritten as intended, but instead of jumping somewhere into the buffer, it jumped into argv, I think. gdb showed up the following addresses before strcpy() was called: (gdb) i f Stack level 0, frame at 0xbffff1f0: eip = 0x80483ed in main (victim.c:7); saved eip 0x154b56 source language c. Arglist at 0xbffff1e8, args: argc=2, argv=0xbffff294 Locals at 0xbffff1e8, Previous frame's sp is 0xbffff1f0 Saved registers: ebp at 0xbffff1e8, eip at 0xbffff1ec Address of little_array: (gdb) print &little_array[0] $1 = 0xbfffefe8 "\020" After strcpy(): (gdb) i f Stack level 0, frame at 0xbffff1f0: eip = 0x804840d in main (victim.c:10); saved eip 0xbffff458 source language c. Arglist at 0xbffff1e8, args: argc=-1073744808, argv=0xbffff458 Locals at 0xbffff1e8, Previous frame's sp is 0xbffff1f0 Saved registers: ebp at 0xbffff1e8, eip at 0xbffff1ec So, what happened here? I used a 604 byte buffer to overflow little_array, so he certainly overwrote saved ebp, saved eip and argc and also argv with the guessed address 0xbffff458. Then, after returning, EIP pointed at 0xbffff458. But little_buffer resides at 0xbfffefe8, that`s a difference of 1136 byte, so he certainly isn't executing little_array. I followed execution with the stepi command and well, at 0xbffff458 and onwards, he executes NOPs and reaches the shellcode. I'am not quite sure why this is happening. First of all, am I correct that he executes my shellcode in argv, not little_array? And where does the loader(?) place argv onto the stack? I thought it follows immediately after argc, but between argc and 0xbffff458, there is a gap of 620 bytes. How is it possible that he successfully "lands" in the NOP-Pad at Address 0xbffff458, which is way above the saved eip at 0xbffff1ec? Can someone clarify this? I have actually no idea why this is working. My test-machine is an Ubuntu 9.10 32-Bit Machine without ASLR. victim has an executable stack, set with execstack -s. Thanks in advance.

    Read the article

  • argv Memory Allocation

    - by Joshua Green
    I was wondering if someone could tell me what I am doing wrong that I get this Unhandled Exception error message: 0xC0000005: Access violation reading location 0x0000000c. with a green pointer pointing at my first Prolog code (fid_t): Here is my header file: class UserTaskProlog { public: UserTaskProlog( ArRobot* r ); ~UserTaskProlog( ); protected: int cycles; char* argv[ 1 ]; term_t tf; term_t tx; term_t goal_term; functor_t goal_functor; ArRobot* robot; void logTask( ); }; And here is my main code: UserTaskProlog::UserTaskProlog( ArRobot* r ) : robot( r ), robotTaskFunc( this, &UserTaskProlog::logTask ) { cycles = 0; argv[ 0 ] = "libpl.dll"; argv[ 1 ] = NULL; PL_initialise( 1, argv ); PlCall( "consult( 'myPrologFile.pl' )" ); robot->addSensorInterpTask( "UserTaskProlog", 50, &robotTaskFunc ); } UserTaskProlog::~UserTaskProlog( ) { robot->remSensorInterpTask( &robotTaskFunc ); } void UserTaskProlog::logTask( ) { cycles++; fid_t fid = PL_open_foreign_frame( ); tf = PL_new_term_ref( ); PL_put_integer( tf, 5 ); tx = PL_new_term_ref( ); goal_term = PL_new_term_ref( ); goal_functor = PL_new_functor( PL_new_atom( "factorial" ), 2 ); PL_cons_functor( goal_term, goal_functor, tf, tx ); int fact; if ( PL_call( goal_term, NULL ) ) { PL_get_integer( tx, &fact ); cout << fact << endl; } PL_discard_foreign_frame( fid ); } int main( int argc, char** argv ) { ArRobot robot; ArArgumentParser argParser( &argc, argv ); UserTaskProlog talk( &robot ); } Thank you,

    Read the article

  • Convert TCHAR* argv[]

    - by sijith
    i want to enter a text into TCHAR* argv[], how its possible to do. OR how to convert from a charater to TCHAR* argv[]. Please help char randcount[]="Hello world"; want to convert to TCHAR* argv[]

    Read the article

  • When can argv[0] have null ?

    - by andrew-dufresne
    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 null string? I mean program name with its path will always be available so when can it be null? Writer says that "if that is not available" but when and how it is possible that program name will not be available? Thanks for your time and support. Regards

    Read the article

  • PHP syntax question: global $argv, $argc;

    - by Andrew
    So I have a PHPUnit test, and found this code within a function. global $argv, $argc; echo $argc; print_r($argv); I understand what these variables represent (arguments passed from the command line), but I've never seen this syntax before:global $argv, $argc; What specifically is going on here?

    Read the article

  • argv[1] loadImage problem xcode 3.2 and snow leopard

    - by ignacionieto
    Hi Im on mac snow leopard and test these code on xcode3.2 of the Learning OpenCV everything works fine but the image doesnt appear and in the windows. I had try to understand searching for two days what does argv[1] means, but Im still no clear. Im a newbie en C++. I had the image in the same directory where the main.cpp is #include <OpenCV/cv.h> #include <OpenCV/highgui.h> int main(int argc, char** argv) { IplImage* interest_img; CvRect interest_rect; if( argc == 7 && ((interest_img= cvLoadImage( argv[1],1) ) != 0 )) { A more easy example is here: http://books.google.cl/books?id=seAgiOfu2EIC&pg=PA17&lpg=PA17&dq=cvLoadImage%28argv[1]&source=bl&ots=hRJ5bhkAOf&sig=gyYAqZBnS6lCCXJz9Fz7vzOsF-U&hl=es&ei=dvdvS-fWG8eWtgePy_WCBg&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBwQ6AEwBTgK#v=onepage&q=cvLoadImage%28argv[1]&f=false both I have test it but they dont work. Please help me

    Read the article

  • Compare _TCHAR* argv[] entries from command line to _T("paramString")

    - by David
    I know how to get the parameters from the command line. I also know how to print them out. The problem I'm having is how to compare the parameters from the argv[] array to a string. The progam runs but never returns a result where the parameter string is equal to the one I'm looking for. Thanks in advance. // Testing.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { for (int i = 0; i < argc; i = i + 1) { if (argv[i] == _T("find")) { wcout << "found at position " << i << endl; } else { wcout << "not found at " << i << endl; } } return 0; }

    Read the article

  • Enthought Canopy - passing sys.argv from PySide Qt program

    - by user2541559
    I've recently been looking at the Enthought distro of iPython. Today I decided to see if I could get some Qt GUI progs running and was successful after making minor changes. Simple example: import sys from PySide import QtGui # was 'from PyQT4 import QtGui' # app = QtGui.QApplication(sys.argv) -- not needed win = QtGui.QWidget() win.resize(320, 240) win.setWindowTitle("Hello MIT 6X!") win.show() sys.exit() # was 'sys.exit(app.exec_())' But I would like to be able to pass sys.argv in some cases. Most example code I see is in the form of the commented out 'app = ' line above. If I include it, I get 'RuntimeError: A QApplication instance already exists.' Suggestions for passing arguments appreciated. Nick

    Read the article

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

    - by chrissygormley
    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 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(module)) return alltests if __name__ == '__main__': Run = MyScript() Run.hello() log_file = 'log_file.txt' test_file = open(log_file, "w") runner = unittest.TextTestRunner(test_file) unittest.main(defaultTest='Run.suite', testRunner=runner) Say I enter ./script.py Hello in the command line. The error I get is: AttributeError: 'module' object has no attribute 'Hello' If I remove the unittest module it works. Also if I remove the testrunner log and leave it at: unittest.main(defaultTest='Run.suite') This still doesn't work. Can anyone help. Thanks

    Read the article

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

    - by Greg Treleaven
    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?

    Read the article

  • Accessing variable from ARGV

    - by snaken
    I'm writing a cPanel postwwwact script, if you're not familiar with the script its run after a new account is created. it relies on the user account variable being passed to the script which i then use for various things (creating databases etc). However, I can't seem to find the right way to access the variable i want. I'm not that good with shell scripts so i'd appreciate some advice. I had read somewhere that the value i wanted would be included in $ARGV{'user'} but this simply gives "root" as opposed to the value i need. I've tried looping through all the arguments (list of arguments here) like this: #!/bin/sh for var do touch /root/testvars/$var done and the value i want is in there, i'm just not sure how to accurately target it. There's info here on doing this with PHP or Perl but i have to do this as a shell script. EDIT Ideally i would like to be able to call the variable by something other than $1 or $2 etc as this would create issues if an argument is added or removed Any ideas?

    Read the article

  • range of line numbers in if condition C programming

    - by nour
    Hello, I'm working on a simple C prorgam, and i'ms tuck with an if test: int line_number = 0; if ((line_number >= argv[2]) && (line_number <= argv[4]) ) gcc says: cp.c:25: warning: comparison between pointer and integer cp.c:25: warning: comparison between pointer and integer What can I do to properly write the range of line I want to deal with ? Thank you!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >