1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ - Opening a .bat - C++

Discussion in 'C++' started by kim00000, Oct 8, 2009.

  1. kim00000

    kim00000 New Member

    Joined:
    Oct 8, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi all ,This Is kim00000 :D

    I just need help with this:


    I made a Programme which make a Batch (.bat) File ,which has some commands ,
    So i want the Programme to run that (.bat) file after creating it ,but without defining
    the batch-file's directory ,cause it'll create it at the same path that the programme is in ,

    Example:
    Open("Temp.bat");

    ,,,
    Kim00000
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    You can do that this way :

    Code:
    system("Temp.bat");
    
    In case, you need to provide full path to the bat file, remember to use double backslashes (\\) instead of a single one (\) in the path. For example :

    Code:
    system("C:\\Temp\\Temp.bat");
    
     
  3. kim00000

    kim00000 New Member

    Joined:
    Oct 8, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    But i don't want to define the Path ,i mean that i need a code that opens that file at the same path of the programme.

    Example:The programme is in that path C:\\CPP\\CPP.exe in my computer ,but if i ran it on another computer of course it won't be at the same path as my computer's ,so the system will not find the file C:\\CPP\\Temp.bat given that the Temp.bat is in another location.

    got it? :D
     
  4. kim00000

    kim00000 New Member

    Joined:
    Oct 8, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Sorry for the double Replies ,but i won't to explain in more simple way :D

    1)The Programme is running.
    2)Temp.bat has been made at the same path as the programme's one. :p

    the third one is that i need ,if the path i've provided is C:\\Temp.bat ,and i moved the programme to D:\\ ,the (.bat) file will be created in D:\\ ,so no Temp.bat well be found at C:\\ :D


    simply:

    system("%CPP.exe path%~~\\Temp.bat");


    GOT IT? :cuss:
     

Share This Page