LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 10: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-29-2007, 11:24 PM   #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-29-2007, 11:42 PM   #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, 01:08 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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, 10: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 10:55 PM.
 
  


Reply



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 07:36 PM
how do I find out the current working directory? nodger Programming 2 12-26-2004 11:28 AM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 11:05 AM
current working directory in ksh prompt brian0918 Linux - Newbie 2 06-03-2003 04:34 PM
current working directory in ksh prompt brian0918 Linux - Software 2 06-03-2003 01:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 PM.

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
Open Source Consulting | Domain Registration