Link to home
Start Free TrialLog in
Avatar of sakuya_su
sakuya_su

asked on

chdir not working?

I have the following code:

cout << cmd;
int i;
i = chdir(&cmd[0]);
printf("%d", i);

now the cout line produce:
/home/sakuya/Documents/University/159.101/work/a6/

but the directory isnt changed in the console window... Am I doing something wrong?

thanks in advanced
Avatar of rajeev_devin
rajeev_devin

post your complete code
Avatar of sakuya_su

ASKER

cmd = "/home/sakuya/Documents/University/";
            cmd += "159.101/work/";
            cmd += argv[2];
            cmd += "/";


And

if ( strcmp(argv[3], "in") == 0 )
      {
            //CD in to the directory only
            //printf("%s", run);
            cout << "-----------change Dir-------------" << endl;
            //run = &cmd[0];
            //printf("%s", run);
            int i;
            i = chdir(&cmd[0]);
            printf("%d", i);
      }
SOLUTION
Avatar of rajeev_devin
rajeev_devin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ah i see whats happening now,

is there a way to change the current directory of the console window?
"
ah i see whats happening now,

is there a way to change the current directory of the console window?
"

SetCurrentDirectory() ;
>> SetCurrentDirectory() ;
First, of all SetCurrentDirectory() is a windows API. So, it cannot be used in Linux.
Second, It changes the current directory of the process from where it is called. It won't change the current directory of console.
system("cd [PATH]");

Should do it?
no system("cd PATH"); does not work

to  M_, i need to the code to be able to work under Linux.

rajeev_devin, do you have any idea how to do this?

Thanks for all your help
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
heh yeah, i think i'll just create a batch with a CD command in it
>> heh yeah, i think i'll just create a batch with a CD command in it
That won't do either.
By the way in which platform you are working ?
Linux
In linux can you do something like "DLL Hooking in Windows" ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i'll try the . *.sh tomorrow, thanks,

to rajeev, no, there are no dll hooks in linux
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
which other methods are u refering to?
If all you want to do in your program is change the CWD to something specific, then there is no reason to write a C++ program to do it.  Just use a batch file (or, in Unix, a shell script).

     REM QCD.BAT (Quick Change Dir)
     REM Batch file to do everything without writing a C++ program
     REM Syntax:   QCD string
     REM Example: QCD a6
     CD /home/sakuya/Documents/University/159.101/work/%1

The above lines will save you lots of typing.  The %1 in the CD command is replaced by whatever you type at the end of the QCD command line.  You can remove the REM lines if you want.
well it seems no one has produced a very useable suggestion, but the comments here got me thinking and I have then coded my program arround this area.

so I'll split point to all who made a contribution.

thanks