From owner-freebsd-questions@FreeBSD.ORG Wed Apr 5 06:29:46 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD8E916A422 for ; Wed, 5 Apr 2006 06:29:46 +0000 (UTC) (envelope-from usleepless@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.195]) by mx1.FreeBSD.org (Postfix) with ESMTP id E53CD43D46 for ; Wed, 5 Apr 2006 06:29:45 +0000 (GMT) (envelope-from usleepless@gmail.com) Received: by zproxy.gmail.com with SMTP id l8so200917nzf for ; Tue, 04 Apr 2006 23:29:45 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=akbGoB64ja6G2rUFxhM9h9DkqTv0LaXGdc+BsBzN3h9jv+556c33HxT73SwYBQCgDtjX9pQALlO8j3bBgvgNse+/O78uceeBjp3Lkw7jmZVRvM1js+jFtGC0ZfI9/oZkwhU85XQOO01AV0tgIEzpmpldEFFaN4aHWuO/Qf73R/U= Received: by 10.36.57.16 with SMTP id f16mr1863875nza; Tue, 04 Apr 2006 23:29:45 -0700 (PDT) Received: by 10.36.158.2 with HTTP; Tue, 4 Apr 2006 23:29:45 -0700 (PDT) Message-ID: Date: Wed, 5 Apr 2006 08:29:45 +0200 From: usleepless@gmail.com To: "Jonathan Herriott" In-Reply-To: <6a56d69c0604041833y1f12fd43uc916f852128baeb5@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6a56d69c0604031439o7c2eed8an5710dad733a0e97@mail.gmail.com> <20060403174519.4d478a95.wmoran@collaborativefusion.com> <20060403220419.GA5042@epia2.farid-hajji.net> <6a56d69c0604041402i456d33cfm2c6f571e5c558e@mail.gmail.com> <6a56d69c0604041833y1f12fd43uc916f852128baeb5@mail.gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: C Program to execute programs in same console X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Apr 2006 06:29:46 -0000 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 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, usleepless@gmail.com 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 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 wrote: > > > > On Mon, Apr 03, 2006 at 05:45:19PM -0400, Bill Moran wrote: > > > > > On Mon, 3 Apr 2006 21:39:11 +0000 > > > > > "Jonathan Herriott" 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 g= ive > me > > > > > > a term to search for or a function to look up. I'm sure someon= e > 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 'c= d' > > > > command could work? Of look at how expect(1) (/usr/ports/lang/expec= t) > > > > 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 > "freebsd-questions-unsubscribe@freebsd.org" > > > > > >