Re: C Program to execute programs in same console

2006-04-05 Thread usleepless
Hi Jon,

could you give another example ( not cd ) of a command which you would
like to execute in the calling shell?

regards,

usleep

On 4/5/06, Jonathan Herriott [EMAIL PROTECTED] wrote:
 usleep,

 What I am trying to do is execute the command in the calling shell.
 So, if I were to execute my program, which changes the directory, it
 would do the following:

  pwd
 /usr/home/username/
  ./myprog ..
  pwd
 /usr/home/

 That's basically what I'm looking for.  Being able to modify the
 calling shell with a program.

 Thanks,
 Jon

 On 4/4/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Jon,
 
  i believe you are mixing up some concepts.
 
  1. if i read your title C Program to execute programs in same
  console. i think this is easy, just use system(ls *.txt) and you
  are done. i believe you can choose wat to do with the output, i am not
  sure.
 
  2. but you come up with the cd-command, which you want to change the
  context of your parent shell.  changing the home-dir of the current
  process ( your program ) can be done with chdir. altering the context
  of your parent-shell-process can not be done, except for setting
  environment variables ( through the proper C calls )
 
  but if you are running your program, your shell (interpreter) is
  temporarily not there:  your program is running the show. every
  system,execvp or whatever call will give you a child-process with a
  new shell, not the parent-shell-process. i believe you may set
  environment variables in your parent shell with the appropiate library
  calls, but not through a system/execvp call.
 
  so, maybe you should define what you really want to achieve. for
  example, qdvd-author runs alls kinds of external programs to generate
  thumbnails and slideshows for example.
 
  anybody please correct me if i am wrong.
 
  regards,
 
  usleep
 
 
  On 4/4/06, Jonathan Herriott [EMAIL PROTECTED] wrote:
   Thanks for the suggestion.  I haven't tried it yet, but I'll post if I
   get it working.
  
   Thanks,
   Jon
  
   On 4/3/06, cpghost [EMAIL PROTECTED] wrote:
On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote:
 On Mon, 3 Apr 2006 21:39:11 +
 Jonathan Herriott [EMAIL PROTECTED] wrote:
  So, my question is how can I get it to execute a cd in the
 current
  shell using c code.  You don't have to give me the code, just give
 me
  a term to search for or a function to look up.  I'm sure someone
 knows
  how to do it here!

 Unless I'm misunderstanding your question, man 2 chdir should
 help
   out.
   
Hmmm... chdir(2) would not change the parent process' (the shell's
process) current working directory, only the current working
 directory
of the process running the C program.
   
Perhaps connecting to the shell via a pty, and then sending it a 'cd'
command could work? Of look at how expect(1) (/usr/ports/lang/expect)
implements this kind of stuff...
   
Regards,
-cpghost.
   
--
Cordula's Web. http://www.cordula.ws/
   
   ___
   freebsd-questions@freebsd.org mailing list
   http://lists.freebsd.org/mailman/listinfo/freebsd-questions
   To unsubscribe, send any mail to
 [EMAIL PROTECTED]
  
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-05 Thread Jonathan Herriott
usleep,

What I am trying to do is execute the command in the calling shell. 
So, if I were to execute my program, which changes the directory, it
would do the following:

 pwd
/usr/home/username/
 ./myprog ..
 pwd
/usr/home/

That's basically what I'm looking for.  Being able to modify the
calling shell with a program.

Thanks,
Jon

On 4/4/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Jon,

 i believe you are mixing up some concepts.

 1. if i read your title C Program to execute programs in same
 console. i think this is easy, just use system(ls *.txt) and you
 are done. i believe you can choose wat to do with the output, i am not
 sure.

 2. but you come up with the cd-command, which you want to change the
 context of your parent shell.  changing the home-dir of the current
 process ( your program ) can be done with chdir. altering the context
 of your parent-shell-process can not be done, except for setting
 environment variables ( through the proper C calls )

 but if you are running your program, your shell (interpreter) is
 temporarily not there:  your program is running the show. every
 system,execvp or whatever call will give you a child-process with a
 new shell, not the parent-shell-process. i believe you may set
 environment variables in your parent shell with the appropiate library
 calls, but not through a system/execvp call.

 so, maybe you should define what you really want to achieve. for
 example, qdvd-author runs alls kinds of external programs to generate
 thumbnails and slideshows for example.

 anybody please correct me if i am wrong.

 regards,

 usleep


 On 4/4/06, Jonathan Herriott [EMAIL PROTECTED] wrote:
  Thanks for the suggestion.  I haven't tried it yet, but I'll post if I
  get it working.
 
  Thanks,
  Jon
 
  On 4/3/06, cpghost [EMAIL PROTECTED] wrote:
   On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote:
On Mon, 3 Apr 2006 21:39:11 +
Jonathan Herriott [EMAIL PROTECTED] wrote:
 So, my question is how can I get it to execute a cd in the current
 shell using c code.  You don't have to give me the code, just give me
 a term to search for or a function to look up.  I'm sure someone knows
 how to do it here!
   
Unless I'm misunderstanding your question, man 2 chdir should help
  out.
  
   Hmmm... chdir(2) would not change the parent process' (the shell's
   process) current working directory, only the current working directory
   of the process running the C program.
  
   Perhaps connecting to the shell via a pty, and then sending it a 'cd'
   command could work? Of look at how expect(1) (/usr/ports/lang/expect)
   implements this kind of stuff...
  
   Regards,
   -cpghost.
  
   --
   Cordula's Web. http://www.cordula.ws/
  
  ___
  freebsd-questions@freebsd.org mailing list
  http://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to [EMAIL PROTECTED]
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-05 Thread Erik Trulsson
On Tue, Apr 04, 2006 at 09:33:04PM -0400, Jonathan Herriott wrote:
 usleep,
 
 What I am trying to do is execute the command in the calling shell. 
 So, if I were to execute my program, which changes the directory, it
 would do the following:
 
  pwd
 /usr/home/username/
  ./myprog ..
  pwd
 /usr/home/
 
 That's basically what I'm looking for.  Being able to modify the
 calling shell with a program.

It is not possible to do that.

A program can only change its own working directory, not that of other
programs.



-- 
Insert your favourite quote here.
Erik Trulsson
[EMAIL PROTECTED]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-05 Thread Alex Zbyslaw

Jonathan Herriott wrote:

What I am trying to do is execute the command in the calling shell. 
So, if I were to execute my program, which changes the directory, it

would do the following:


pwd
   


/usr/home/username/
 


./myprog ..
pwd
   


/usr/home/

That's basically what I'm looking for.  Being able to modify the
calling shell with a program.
 

Write a shell script.  If using sh/bash? run it as . shellscript or if 
csh source shellscript.  You can then make aliases (at least in csh) 
like so:

   alias foo source shellscript

Then when you type foo, any cd inside the shellscript will affect your 
current shell.


e.g.

% cat foo.sh
cd ..
% alias foo source foo.sh
% pwd
/tmp
% foo
% pwd
/
%

This is a rubbish alias since it only works if you are in the same 
directory as the shellscript, but I'm sure you can do better :-)


To my mind you are still explaining the solution you have come up with 
for some problem, but have not actually explained the original problem.  
Your solution is generally impossible since one process (your C 
program) cannot arbitrarily affect the running environment (the current 
directory) of another process (your shell).


--Alex

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-04 Thread Jonathan Herriott
Thanks for the suggestion.  I haven't tried it yet, but I'll post if I
get it working.

Thanks,
Jon

On 4/3/06, cpghost [EMAIL PROTECTED] wrote:
 On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote:
  On Mon, 3 Apr 2006 21:39:11 +
  Jonathan Herriott [EMAIL PROTECTED] wrote:
   So, my question is how can I get it to execute a cd in the current
   shell using c code.  You don't have to give me the code, just give me
   a term to search for or a function to look up.  I'm sure someone knows
   how to do it here!
 
  Unless I'm misunderstanding your question, man 2 chdir should help out.

 Hmmm... chdir(2) would not change the parent process' (the shell's
 process) current working directory, only the current working directory
 of the process running the C program.

 Perhaps connecting to the shell via a pty, and then sending it a 'cd'
 command could work? Of look at how expect(1) (/usr/ports/lang/expect)
 implements this kind of stuff...

 Regards,
 -cpghost.

 --
 Cordula's Web. http://www.cordula.ws/

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-04 Thread usleepless
Jon,

i believe you are mixing up some concepts.

1. if i read your title C Program to execute programs in same
console. i think this is easy, just use system(ls *.txt) and you
are done. i believe you can choose wat to do with the output, i am not
sure.

2. but you come up with the cd-command, which you want to change the
context of your parent shell.  changing the home-dir of the current
process ( your program ) can be done with chdir. altering the context
of your parent-shell-process can not be done, except for setting
environment variables ( through the proper C calls )

but if you are running your program, your shell (interpreter) is
temporarily not there:  your program is running the show. every
system,execvp or whatever call will give you a child-process with a
new shell, not the parent-shell-process. i believe you may set
environment variables in your parent shell with the appropiate library
calls, but not through a system/execvp call.

so, maybe you should define what you really want to achieve. for
example, qdvd-author runs alls kinds of external programs to generate
thumbnails and slideshows for example.

anybody please correct me if i am wrong.

regards,

usleep


On 4/4/06, Jonathan Herriott [EMAIL PROTECTED] wrote:
 Thanks for the suggestion.  I haven't tried it yet, but I'll post if I
 get it working.

 Thanks,
 Jon

 On 4/3/06, cpghost [EMAIL PROTECTED] wrote:
  On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote:
   On Mon, 3 Apr 2006 21:39:11 +
   Jonathan Herriott [EMAIL PROTECTED] wrote:
So, my question is how can I get it to execute a cd in the current
shell using c code.  You don't have to give me the code, just give me
a term to search for or a function to look up.  I'm sure someone knows
how to do it here!
  
   Unless I'm misunderstanding your question, man 2 chdir should help
 out.
 
  Hmmm... chdir(2) would not change the parent process' (the shell's
  process) current working directory, only the current working directory
  of the process running the C program.
 
  Perhaps connecting to the shell via a pty, and then sending it a 'cd'
  command could work? Of look at how expect(1) (/usr/ports/lang/expect)
  implements this kind of stuff...
 
  Regards,
  -cpghost.
 
  --
  Cordula's Web. http://www.cordula.ws/
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


C Program to execute programs in same console

2006-04-03 Thread Jonathan Herriott
Hi!

I've come into an interesting problem I've been trying to figure out. 
For no other reason than my own interest, I've been trying to get a c
program to execute other programs in the current console I am in
(using kde if that helps).

I tried using system() and execvp() calls to try and execute a cd
command in my current shell, which of course, didn't work.  It seems
to open up a new shell, then execute the command, and then exit that
new shell it had opened.

So, my question is how can I get it to execute a cd in the current
shell using c code.  You don't have to give me the code, just give me
a term to search for or a function to look up.  I'm sure someone knows
how to do it here!

Thanks in advance for the help!

Jon
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-03 Thread Bill Moran
On Mon, 3 Apr 2006 21:39:11 +
Jonathan Herriott [EMAIL PROTECTED] wrote:
 
 I've come into an interesting problem I've been trying to figure out. 
 For no other reason than my own interest, I've been trying to get a c
 program to execute other programs in the current console I am in
 (using kde if that helps).
 
 I tried using system() and execvp() calls to try and execute a cd
 command in my current shell, which of course, didn't work.  It seems
 to open up a new shell, then execute the command, and then exit that
 new shell it had opened.
 
 So, my question is how can I get it to execute a cd in the current
 shell using c code.  You don't have to give me the code, just give me
 a term to search for or a function to look up.  I'm sure someone knows
 how to do it here!

Unless I'm misunderstanding your question, man 2 chdir should help out.

-- 
Bill Moran
Collaborative Fusion Inc.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: C Program to execute programs in same console

2006-04-03 Thread cpghost
On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote:
 On Mon, 3 Apr 2006 21:39:11 +
 Jonathan Herriott [EMAIL PROTECTED] wrote:
  So, my question is how can I get it to execute a cd in the current
  shell using c code.  You don't have to give me the code, just give me
  a term to search for or a function to look up.  I'm sure someone knows
  how to do it here!
 
 Unless I'm misunderstanding your question, man 2 chdir should help out.

Hmmm... chdir(2) would not change the parent process' (the shell's
process) current working directory, only the current working directory
of the process running the C program.

Perhaps connecting to the shell via a pty, and then sending it a 'cd'
command could work? Of look at how expect(1) (/usr/ports/lang/expect)
implements this kind of stuff...

Regards,
-cpghost.

-- 
Cordula's Web. http://www.cordula.ws/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]