Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-06

exec with many params

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antal

in linux I can't use the exec for executing a program with more than one parameter.
I tried to supply more than a parameter separeted with whitespace, but it's not reliable, since the program is treating it as just one parameter

so I can't pass options to programs, such as:
ls -l .*

Reply by email

Antal

in linux I can't use the exec for executing a program with more than one parameter.
I tried to supply more than a parameter separeted with whitespace, but it's not reliable, since the program is treating it as just one parameter

so I can't pass options to programs, such as:
ls -l .*

Reply by email

Peter Vreman
to Antal
Show quoted text 7 lines
in linux I can't use the exec for executing a program with more than one parameter. I tried to supply more than a parameter separeted with whitespace, but it's not reliable, since the program is treating it as just one parameter so I can't pass options to programs, such as: ls -l .*

Expansion of the * is done by the shell not by the exec system call. Use the shell() command from the unix unit instead.

Reply by email

Antal
Show quoted text 10 lines
> in linux I can't use the exec for executing a program with more than one > parameter. > I tried to supply more than a parameter separeted with whitespace, but > it's not reliable, since the program is treating it as just one parameter > > so I can't pass options to programs, such as: > ls -l .* Expansion of the * is done by the shell not by the exec system call. Use the shell() command from the unix unit instead.

I'm not asking about a shell related problem, but about passing more than a single parameter when executing a file
let's change the above example to
cat ~/anyfile1 ~/anyfile2
or just:
dir /p c:

or anything else, which needs many params

Anyway, if using the shell() would help in linux, it's a good hint. But for portability what do I do in other OS?

I'm just pointing out the more than one parameter execution of a command

Reply by email

Florian Klaempfl
to Antal
Antal wrote 24 lines
>>in linux I can't use the exec for executing a program with more than one >>parameter. >>I tried to supply more than a parameter separeted with whitespace, but >>it's not reliable, since the program is treating it as just one parameter >> >>so I can't pass options to programs, such as: >>ls -l .* > >Expansion of the * is done by the shell not by the exec system call. Use >the shell() command from the unix unit instead. I'm not asking about a shell related problem, but about passing more than a single parameter when executing a file let's change the above example to cat ~/anyfile1 ~/anyfile2 or just: dir /p c: or anything else, which needs many params Anyway, if using the shell() would help in linux, it's a good hint. But for portability what do I do in other OS? I'm just pointing out the more than one parameter execution of a command

The compiler uses executeprocess heavily and it works fine. Please provide a complete example which doesn't work.

Reply by email

Marco van de Voort
to Antal: I'm not asking about a shell related problem, but about passing more than a single…
Show quoted text 12 lines
a single parameter when executing a file let's change the above example to cat ~/anyfile1 ~/anyfile2 or just: dir /p c: or anything else, which needs many params Anyway, if using the shell() would help in linux, it's a good hint. But for portability what do I do in other OS? I'm just pointing out the more than one parameter execution of a command

There are three different things that could be wrong:

1. you are using the wrong function, or using it the wrong way. Show code.
2. Under unix, when executing _directly_ parameters are not separated by whitespace but as separate arguments.
3. Under Unix, programs typically don't process things like ? and *, the shell does. So if you do something with a *, you _must_ go via the shell, unless you 100% certain know that the program accepts *'s directly (most don't, including ls)

Note to 3 So if I do

ls -l *.bla

the shell does this:
- it expands "ls" to the full path /usr/bin/ls
- it expands all * and ?, fills in environment variables etc, so *.bla becomes file1.bla file2.bla file3.bla etc.
- it parses the parameters into separate arguments
- it calls exec. In this example with three *.bla files, ls -l *.bla would result in the shell calling the exec function like this:

	execv('/usr/bin/ls','-l','file1.bla','file2.bla','file3.bla');

So always keep what you write on the commandline, and how you execute in an Unix program apart. If you don't want that, execute via the shell (the call is named fpsystem(), shell() is an older 1.x compability call)

Reply by email

Marco van de Voort
to Antal: in linux I can't use the exec for executing a program with more than one parameter. I…
in linux I can't use the exec for executing a program with more than one parameter.

"the exce" ? Which exec? Can you provide an example?

Show quoted text 5 lines
I tried to supply more than a parameter separeted with whitespace, but it's not reliable, since the program is treating it as just one parameter so I can't pass options to programs, such as: ls -l .*
sysutils.executeprocess ('/bin/ls',['-l','.*']);

fpexecl is also possible, but why not use relative OS independant functionality ?

Reply by email

Michael Van Canneyt
to Antal: in linux I can't use the exec for executing a program with more than one parameter. I…
Antal wrote 7 lines
in linux I can't use the exec for executing a program with more than one parameter. I tried to supply more than a parameter separeted with whitespace, but it's not reliable, since the program is treating it as just one parameter so I can't pass options to programs, such as: ls -l .*

Which exec call is this ?

First of all; .* is normally handled by the shell. Secondly, parameters are passed as an array of PChar pointers.

Michael.

Reply by email