LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-29-2007, 11:28 PM   #1
g4j31a5
Member
 
Registered: Sep 2006
Distribution: open SuSE 10.0
Posts: 116

Rep: Reputation: 15
How to change current working directory in C++?


Hi, I want to know how can I change the working directory in C++? I have a system call that executes LaTeX to make a PostScript file. But everytime I call that method, LaTeX made its files (.aux, .log, .dvi, and .ps) in the same directory as the executable. I wanted to be able to call LaTeX from another directory so LaTeX will make its files inside that directory. So, how do I do that?

Thanks in advance.
 
Old 04-30-2007, 12:24 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
C++ itself doesn't support such requirements. However you can perform it using the specific OS command, and the system() function call.
 
Old 04-30-2007, 12:42 AM   #3
g4j31a5
Member
 
Registered: Sep 2006
Distribution: open SuSE 10.0
Posts: 116

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by graemef
C++ itself doesn't support such requirements. However you can perform it using the specific OS command, and the system() function call.
I thought so too. BTW, I've been doing some man and info browsing and found out about setenv. So maybe I can do it like this:
Code:
setenv("PWD","./Temp/", 1);
system("latex ....");
Haven't tried it yet though. Thanks.
 
Old 04-30-2007, 02:08 AM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Actually, I would look at chdir(2). For example:
Code:
#include <unistd.h>

int main(int argc,char **argv){
    chdir("/new/working/directory");
    return 0;
}
 
Old 05-09-2007, 11:18 PM   #5
g4j31a5
Member
 
Registered: Sep 2006
Distribution: open SuSE 10.0
Posts: 116

Original Poster
Rep: Reputation: 15
Thanks Matir, I've looked at the manpage of chdir. I think it's just the one I need. Thanks alot for the help.

Last edited by g4j31a5; 05-09-2007 at 11:55 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change profile to show current directory jpolachak Linux - Newbie 2 01-20-2005 08:36 PM
how do I find out the current working directory? nodger Programming 2 12-26-2004 12:28 PM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 12:05 PM
current working directory in ksh prompt brian0918 Linux - Newbie 2 06-03-2003 05:34 PM
current working directory in ksh prompt brian0918 Linux - Software 2 06-03-2003 02:50 PM


All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration