Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 01-11-2008, 07:39 PM   #1 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Problem with system() function in C


I want to run a program that has to rename a folder H:\gk1\gk1 to gk2
When I run that command using
system("move H:\gk1\gk1 gk2");

it reports an error that "Bad command or file name" .
I even tried the rename command it give "Invalid path or filename"
The specified folder exists and no other application is using it.
If I run the same command from the command prompt it executes.
Please help me..I'm struck with my prog.
__________________
blogging at http://gkbhat.blogspot.com
gk2k is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 01-11-2008, 07:46 PM   #2 (permalink)
Human Spambot
 
swatkat's Avatar
 
Join Date: Mar 2004
Location: India
Posts: 2,033
Default Re: Problem with system() function in C

Hmmm... This worked for me:
Code:
system( "ren c:\\gk1\\gk1 gk2" );
Give two back-slashes (\\). In your code, the character "g" gets escaped...
__________________
http://swatrant.blogspot.com/
swatkat is offline  
Old 02-11-2008, 07:29 AM   #3 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Re: Problem with system() function in C

I tried that it gives error "Invalid Path or filename"
Even the cd command gives"Invalid directory"
I've attached my code here
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
system( "dir/p/a");
system( "cd gk1" );
system( "dir/p/a");
system( "rename c:\\gk1\\gk1 gk2" );
getch();
return 0;
}
I execute this programme in C:\ directory
__________________
blogging at http://gkbhat.blogspot.com

Last edited by gk2k; 02-11-2008 at 04:43 PM.
gk2k is offline  
Old 02-11-2008, 09:00 AM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Problem with system() function in C

Shouldn't there be space between a command and its arguments?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 02-11-2008, 04:47 PM   #5 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Re: Problem with system() function in C

Which command are you pointing to?
If it's dir/p/a it can be given without space also
__________________
blogging at http://gkbhat.blogspot.com
gk2k is offline  
Old 15-11-2008, 10:11 AM   #6 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Re: Problem with system() function in C

Any help please?
__________________
blogging at http://gkbhat.blogspot.com
gk2k is offline  
Old 15-11-2008, 10:42 AM   #7 (permalink)
In The Zone
 
parthbarot's Avatar
 
Join Date: Sep 2004
Location: .::OnLine::.
Posts: 388
Default Re: Problem with system() function in C

i think only 2 things...

1. Must use #include <stdlib.h>
2. If command runs on DOS then must run through system command...
and it will move ( move H:\gk1\gk1 gk2 ) in the current directory... i tried...it worked...

regards.
__________________
www.techlads.com

Paarth.
parthbarot is offline  
Old 15-11-2008, 03:27 PM   #8 (permalink)
The Smaller Bang
 
MetalheadGautham's Avatar
 
Join Date: Sep 2007
Location: Gautham City
Posts: 7,489
Default Re: Problem with system() function in C

You are supposed to insert the FULL address in both the source and the destination.
__________________
http://TheSmallerBang.wordpress.com
eMachines E725 - T4400 2.2GHz, 1GB, 160GB
Nokia 5130XM * T-Sonic 610 2GB
Nokia 2323C * Samsung Galaxy Y
Apple iPad 2 16GB WiFi
MetalheadGautham is offline  
Old 17-11-2008, 03:00 PM   #9 (permalink)
In The Zone
 
parthbarot's Avatar
 
Join Date: Sep 2004
Location: .::OnLine::.
Posts: 388
Default Re: Problem with system() function in C

i dnt think so.... because it will make the new folder 'gk2' in the current folder itself...so it does't matter i think...

regards.
__________________
www.techlads.com

Paarth.
parthbarot is offline  
Old 17-11-2008, 03:15 PM   #10 (permalink)
The Smaller Bang
 
MetalheadGautham's Avatar
 
Join Date: Sep 2007
Location: Gautham City
Posts: 7,489
Default Re: Problem with system() function in C

^^Exactly. But what is that your intention in the first place ?

And one more question: Doesn't the system() function accept an array of characters as an arguement and executes the statement in the array as a command in the shell ? So this is an OS dependant question which has little to do with programming error and more to do with the OS he uses.
__________________
http://TheSmallerBang.wordpress.com
eMachines E725 - T4400 2.2GHz, 1GB, 160GB
Nokia 5130XM * T-Sonic 610 2GB
Nokia 2323C * Samsung Galaxy Y
Apple iPad 2 16GB WiFi
MetalheadGautham is offline  
Old 17-11-2008, 03:25 PM   #11 (permalink)
Alpha Geek
 
Krazy_About_Technology's Avatar
 
Join Date: Jun 2004
Location: Noida - India
Posts: 765
Default Re: Problem with system() function in C

If you are running it from within the compiler IDE the system() function won't work. Compile the program and then run the exe from commandline. You can find out where the output exe is produced in the configuration dialog of your compiler. I assume you are using the same age old Turbo C++ (Yuck!) IDE so you can go to Options>Directories and look at the value of Output Directory. if nothing is there then the output executable will be created in the bin directory of your compiler installation folder.
__________________
Dell Inspiron 1525 - C2D 2 Ghz, 3GB, 250GB, X3100 :)

Samsung Omnia Pro B7610 with Stock WM 6.1 ROM

Blog: http://www.sumitbhardwaj.co.in/blog
Krazy_About_Technology is offline  
Old 20-11-2008, 07:48 AM   #12 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Re: Problem with system() function in C

@MetalheadGautham
I just want to write a program to rename a folder taking old and new folder name as argument.I didn't get a built in c function to rename the folder.

Some commands like "dir" works.I use tc with windows xp.
@Krazy_About_Technology
I run the exe through the command line only.
__________________
blogging at http://gkbhat.blogspot.com
gk2k is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with command line problem dead_eye Software Q&A 3 29-09-2008 09:06 PM
problem with command prompt dhiraj_ Software Q&A 10 08-09-2008 11:37 PM
system command c/c++ internet.sid Programming 2 17-08-2008 09:56 PM
command prompt problem bukaida QnA (read only) 2 22-01-2006 08:26 PM

 
Latest Threads
- by topgear
- by Charan

Advertisement




All times are GMT +5.5. The time now is 05:54 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2