|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Changing directory, running another program
abc.exe exists in C:\test\abc. abc.exe runs and returns to the C:\test\abc directory.
This is causing a problem with abc.exe; I need my proposed program to run abc.exe and then change directory to C:\test before exiting. It's something that could be done in two lines with a dos bat file, however my program must be a .exe. I tried making a console app that basicall did this: // test9.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { system("c:\\test\\abc.exe"); system("cd c:\\test"); return 0; } This calls abc.exe, but doesn't change the current directory to c:\test. any assistance/pointers are appreciated. Thanks. TIA |
|
#2
|
|||
|
|||
|
it does not change the directory because the system call spawns another process which has this working dir then, but immediately quits.
try "chdir()" instead. did this help?
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
||||
|
||||
|
Code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
system("C:\\windows\\notepad.exe");
chdir("C:\\windows\\desktop");
return 0;
}
Compiling... test9.cpp D:\c\test9\test9.cpp(12) : error C2065: 'chdir' : undeclared identifier Error executing cl.exe. test9.exe - 1 error(s), 0 warning(s) |
|
#4
|
|||
|
|||
|
#include <unistd.h>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Changing directory, running another program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|