C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 10th, 2002, 04:47 PM
C3P0's Avatar
C3P0 C3P0 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 302 C3P0 User rank is Private First Class (20 - 50 Reputation Level)C3P0 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 21 h 38 m 27 sec
Reputation Power: 7
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

Reply With Quote
  #2  
Old May 11th, 2002, 04:17 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
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.

Reply With Quote
  #3  
Old May 16th, 2002, 10:19 AM
C3P0's Avatar
C3P0 C3P0 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 302 C3P0 User rank is Private First Class (20 - 50 Reputation Level)C3P0 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 21 h 38 m 27 sec
Reputation Power: 7
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)

Reply With Quote
  #4  
Old May 16th, 2002, 12:24 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
#include <unistd.h>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Changing directory, running another program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway