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/Uni versity/15 9.101/work /a6/
but the directory isnt changed in the console window... Am I doing something wrong?
thanks in advanced
cout << cmd;
int i;
i = chdir(&cmd[0]);
printf("%d", i);
now the cout line produce:
/home/sakuya/Documents/Uni
but the directory isnt changed in the console window... Am I doing something wrong?
thanks in advanced
post your complete code
ASKER
cmd = "/home/sakuya/Documents/Un iversity/" ;
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);
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ah i see whats happening now,
is there a way to change the current directory of the console window?
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() ;
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.
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?
Should do it?
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
That won't do either.
By the way in which platform you are working ?
ASKER
Linux
In linux can you do something like "DLL Hooking in Windows" ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i'll try the . *.sh tomorrow, thanks,
to rajeev, no, there are no dll hooks in linux
to rajeev, no, there are no dll hooks in linux
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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/Uni versity/15 9.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.
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/Uni
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.
ASKER
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
so I'll split point to all who made a contribution.
thanks