- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Using system Function call in HP UNIX
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:07 AM
тАО02-21-2008 06:07 AM
I want to rename a file in a C++ Program.
So i am using the system function call as follows .
int amin()
{
string src="Test.txt";
string Dest = "Test_1.txt"
system("mv Src Dest");
}
But if i execute the program the error message saying Src no such file or directory is displayed.
I also tried to do this by calling a shell script in the system function call as follows
int amin()
{
string src="Test.txt";
string Dest = "Test_1.txt"
system("./Move.sh Src Dest");
}
Move.sh is as follows
mv $1 $2
But, again the same error.
Can some one help me to achive this.
thanks in advance
Vikram
Solved! Go to Solution.
- Tags:
- system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:15 AM
тАО02-21-2008 06:15 AM
Re: Using system Function call in HP UNIX
system("mv Src Dest");
# mv Src Dest
Do you have a file called "Src"?
No? Precisely.
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:29 AM
тАО02-21-2008 06:29 AM
Re: Using system Function call in HP UNIX
Does your environment's PATH reflect where your files reside?
For that matter, why write a C or C++ program only to call 'system()' to rename a file? You should call 'rename()' [assuming that the source and destination reside within the same filesystem].
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:33 AM
тАО02-21-2008 06:33 AM
Re: Using system Function call in HP UNIX
STOP!
Take your fingers from the keyboard and slowly turn around.
Walk to the nearest bookshelf and pick up a basic programmign book.
Any language.
even K&R C would be a good start.
Focus on VARIABLES.
Spend a few quality hours with the books. Now turn back.
But don't touch that compiler just yet.
Look around some first, notably with the 'man' pages.
Specifically type, and read,
man rename
man sprintf
Welcome to the wonderous world of programming!
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:37 AM
тАО02-21-2008 06:37 AM
Solutionif ( rename(Src, Dest) == 0 )
printf("%s renamed to %s\n", Src, Dest);
else
perror("rename");
return 0;
...
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:57 AM
тАО02-21-2008 06:57 AM
Re: Using system Function call in HP UNIX
I can rename the file using rename(). But, now i want it to tar and zip it.
Can any one tell me how to achive this?
system("tar -cvf file.tar file");
Obviously the shell will complain that file not found.
Where file for me is a string variable
initialised to "Temp.txt";
thaks and regards
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:04 AM
тАО02-21-2008 07:04 AM
Re: Using system Function call in HP UNIX
From your initial question:
system("mv Src Dest");
Src and Dest are **NAMES** - not variables from the system point of view!
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:08 AM
тАО02-21-2008 07:08 AM
Re: Using system Function call in HP UNIX
Yes i know these are variables. But, still there is a requirement that i should achive this.
Any way to do this will be great help for us.....
thanks and regards
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:13 AM
тАО02-21-2008 07:13 AM
Re: Using system Function call in HP UNIX
Really? But you don't handle them as variables.
man system:
SYNOPSIS
#include
int system(const char *command);
...
You need to *build* the command string first!
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:27 AM
тАО02-21-2008 07:27 AM
Re: Using system Function call in HP UNIX
> Yes i know these are variables. But, still there is a requirement that i should achive this.
This seems like a purely academic exercise. I agree with both Hein and Torsten's comments which are meant to be helpful. The use of 'system()' to perform shell tasks in a C program says that you may need to rethink your objective and your use of tools.
Regards!
...JRF...