473,833 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use *.* parameter in the exec family functions?

Hi all:
I have one question about the system call under Unix system. I would
like to copy all the files in the current directory to a destination
directory using the following code, but it does not work. Any idea?
Thanks in advance!
if (fork() == 0)
{
execl("/usr/bin/cp", "cp", "*.*", "destinatio n", (char*)0);
}

Nov 14 '05 #1
4 3036
an*****@hotmail .com scribbled the following:
Hi all:
I have one question about the system call under Unix system. I would
like to copy all the files in the current directory to a destination
directory using the following code, but it does not work. Any idea?
Thanks in advance!
if (fork() == 0)
{
execl("/usr/bin/cp", "cp", "*.*", "destinatio n", (char*)0);
}


comp.lang.c reply: Ask in comp.unix.progr ammer.
Off-topic reply: *.* is a feature of the shell, not the Unix system
itself. The way you're doing it, cp attempts to copy a file that is
actually named "*.*". You need to execl() a shell and give "cp *.*
destination" as its parameter.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen
Nov 14 '05 #2
an*****@hotmail .com writes:
I have one question about the system call under Unix system. I would
like to copy all the files in the current directory to a destination
directory using the following code, but it does not work. Any idea?
This newsgroup is for questions about C, not about Unix, but I will
answer nonetheless.
if (fork() == 0)
{
execl("/usr/bin/cp", "cp", "*.*", "destinatio n", (char*)0);
}


First of all, Unix programs don't expand glob patterns in command-line
arguments. They expect their parent (normally the shell) to do it for
them. When you run the above code, cp tries to copy a file named,
literally, "*.*" (without the quotes).

Second, the glob pattern "*.*" will only match files whose name
contains a period. In DOS, there is always a period, even in file
names without extensions ("C:\README" and "C:\README. " are the same
file), so "*.*" will match all files, but it won't in Unix.

Third, execl() may fail, and bad things will probably happen if you
don't exit immediately (preferrably by calling _exit(), not exit())
when it does.

DES
--
Dag-Erling Smørgrav - de*@des.no
Nov 14 '05 #3
an*****@hotmail .com wrote:
# Hi all:
# I have one question about the system call under Unix system. I would
# like to copy all the files in the current directory to a destination
# directory using the following code, but it does not work. Any idea?

Unless you need to do something fancy like redirect stdin or stderr,
you can do with the ANSI C function system(). It will take care of
expanding *.* for you which the exec* functions will not.

Just to remember to 'quote' file names in the system() call that you would
need to quote if typing it in at the command prompt.

# if (fork() == 0)
# {
# execl("/usr/bin/cp", "cp", "*.*", "destinatio n", (char*)0);
# }

int exitcode = system("/usr/bin/cp *.* destination");
if (exitcode!=0) {awk! an error occurred!}

or perhaps

char *destination = ....;
....
static char F[] = "/usr/bin/cp *.* '%s'";
char *f = malloc((sizeof F)+strlen(desti nation));
sprintf(f,F,des tination);
int exitcode = system(f);
free(f);
if (exitcode!=0) {awk! an error occurred!}
--
SM Ryan http://www.rawbw.com/~wyrmwif/
This is one wacky game show.
Nov 14 '05 #4
SM Ryan <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> writes:
an*****@hotmail .com wrote:
Hi all:
I have one question about the system call under Unix system. I would
like to copy all the files in the current directory to a destination
directory using the following code, but it does not work. Any idea?


Unless you need to do something fancy like redirect stdin or stderr,
you can do with the ANSI C function system(). It will take care of
expanding *.* for you which the exec* functions will not.

Just to remember to 'quote' file names in the system() call that you would
need to quote if typing it in at the command prompt.


['#' remapped to '>' yet again]

More precisely, system-specific entity that processes the command
string will presumably take care of expanding wildcards in some
system-specific manner.

<OT>
On Unix-like systems, the system() function invokes the shell,
/bin/sh, with the given command string as an argument. If you don't
go through the shell (e.g., if you use one of the system-specific
exec*() function), your wildcards aren't going to be expanded, and the
literal string is going to be passed directly to the /usr/bin/cp
command, which won't know what to do with it unless there happens to
be a file called "*.*".

And of course, given the usual Unix semantics, this will copy only
files whose names whose names contain a '.' character *and* don't
start with '.' -- which is great if that happens to be what you want.

For more information, try comp.unix.progr ammer.
</OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5297
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each time. The transcript so far is reproduced for your amusement below. To summarise: I've put up a Sudoku-solving program called Sudoku.exe. I want to call it in a php script to solve a puzzle and output the solution. It works fine with...
2
2751
by: Avi Kak | last post by:
Hello: I'd be most grateful if someone could answer the following questions about the exec functions in the os module. 1) How does one get one of the os.exec functions in Python to execute a shell script that includes some sort of a control structure in the shell script itself?
45
2695
by: It's me | last post by:
I am new to the Python language. How do I do something like this: I know that a = 3 y = "a" print eval(y)
3
16951
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
2
8998
by: eczino | last post by:
I currently have a web form posting back to a SQL table using a Stored Procedure. Part of this SP is that it pulls data from another table and inserts a new row into the registration table. I want to have a trigger on the registration table that will fire when the row is inserted which will use the sp_send_cdosysmail sproc to send an e-mail to the user. However, I want to be able to include the value of one of the fields within the...
4
2377
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of which I mean here. Just for a moment, let's just take one definition for one of the
9
2701
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio and run it once you've made sure there is no harmful code. Currently we have several stored procedures which final result is a select with several joins that returns many
6
3637
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but it gave a syntax error ("Invalid syntax") with caret pointing to the 'd' of the def keyword.
26
3668
by: warth33 | last post by:
Hello I have a php site. Some page needs to call an external program. The programs are home made c# applications. It uses to work without problem. For a while. Maybe it work for some hour. Or for a day. Or even for a week. At a certain point, when a php script calls the exe file, the application freezes. The following happens:
0
9796
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10500
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10213
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4422
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.