Make C++ execute a UNIX command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BenTheMan
    New Member
    • Nov 2006
    • 8

    Make C++ execute a UNIX command

    Ok---I was wondering...Is there any way to make C++ execute a UNIX command?

    Like, I generate LaTeX files in my code, file.tex. Then I need to compile the .tex files with ``pdflatex file.tex'' which generates a pdf file, and makes life oh so beautiful.

    Is there a way I can get C++ to tell UNIX to do this without me having to type it in every single time?
  • Silent1Mezzo
    New Member
    • Feb 2007
    • 208

    #2
    Originally posted by BenTheMan
    Ok---I was wondering...Is there any way to make C++ execute a UNIX command?

    Like, I generate LaTeX files in my code, file.tex. Then I need to compile the .tex files with ``pdflatex file.tex'' which generates a pdf file, and makes life oh so beautiful.

    Is there a way I can get C++ to tell UNIX to do this without me having to type it in every single time?
    Use the system() command.

    Comment

    • seforo
      New Member
      • Nov 2006
      • 60

      #3
      It is as easy as follows:

      char * filename = "myfile.tex ";
      char command[100];
      sprintf(command ,"pdflatex %s &",filename) ;
      system(command) ;

      Comment

      • BenTheMan
        New Member
        • Nov 2006
        • 8

        #4
        Bad ass. Thanks a lot.

        BTW if you ever need help with your physics homework (assuming you have any) post in SciForums.com, or scienceforums.n et, and send me a PM.

        Comment

        Working...