Thread: problems calling an executable

  1. #16
    Registered User
    Join Date
    Jun 2006
    Posts
    28
    Quote Originally Posted by Salem
    > if(prob_type=="LIN_KERN")
    Probably because this isn't the way to compare strings.

    The first 3 file descriptors in any process are 0, 1 and 2, which are stdin, stdout and stderr respectively.
    if don't put close() the above are running cool. prob_type can be LIN_KERN or LP. it is strange but it really works causing the execl() to choose right.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Probably because you're also using string constants in the call, like
    Code:
    tsp_sol_call("/home/panos/vrp/concorde/TSP/concorde","concorde","LP",
    				     "/media/hda7/source_vrp/tsp_in.tsp");
    If your compiler / linker folds identical string constants then there really is only one "LP" string in the whole file, and so comparing addresses works (though not for any good reason).
    You may as well have enum { isLP, isLinKern } as the type rather than strings.

    Perhaps the program being run barfs without an open file descriptor, in which case
    Code:
    int fd = open("/dev/null", O_WR );
    dup2( fd, 1 );
    Which should be the equivalent of
    Code:
    /home/panos/vrp/concorde/TSP/concorde /media/hda7/source_vrp/tsp_in.tsp > /dev/null
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Use STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO instead of literal 0, 1 and 2. You never know what weird system you'll want to port to.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. some odd computer problems
    By DavidP in forum Tech Board
    Replies: 14
    Last Post: 03-31-2008, 06:25 AM
  3. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  4. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  5. Altering The Program's Executable?
    By Aidman in forum C++ Programming
    Replies: 7
    Last Post: 12-31-2002, 05:11 AM