Thread: exec with system(..), how to use relative paths?

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    88

    exec with system(..), how to use relative paths?

    Hi!

    (I like to use stdlib and system because I want this portable for Win32 and DOS.)

    To execute an command line application from within my C++ program I use int i = system("C:\\path\\...\\programname.exe parameters..."). So far it works well.

    But the absolute/full path is a bit unreliable. .\\programname.exe doesn't work. Also start .\\programname.exe not.

    How can I use relative paths? (the two applications will be in same directory)

    argv[0] shows the path until ...\\ but I don't know how I can combine argv[0] + programmname.exe as executable string. (guess it won't work this way)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Relative paths should work. Are you sure that the name of the program is correct, and that it really is where you think it is?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    88
    The name was correct.

    You where right, relative paths are working. It was a Visual Studio solution with sub projects.

    Even if both exe where in same folder I needed to copy the console.exe to the subfolder of the starter projects's subdir. When starting from VS the exe needs to be there. When starting directly it was already working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM

Tags for this Thread