Article View: pl.comp.lang.c
Article #358Re: Jak to zrobic????
From: Andrzej Bialecki
Date: Mon, 24 Nov 1997 17:42
Date: Mon, 24 Nov 1997 17:42
45 lines
1922 bytes
1922 bytes
Krzysztof Murkowski (murek@ml.put.poznan.pl) wrote:
: Tomasz Grabowski wrote:
: >
: > Mam jakis ciag znakow *argvc[] - niech to bedzie np. nazwa pliku
: > "plik.txt". Teraz chcialbym (pod Unixem) aby moj program odpalil np.
: > program "vi" wraz z ta nazwa "plik.txt". Ktos wie jak to sie robi???
: #include <stdlib.h>
: ...
: char string[100];
: ...
: system( strcat(strcpy( string, "/usr/bin/vi "), argvc[0] ) );
...lub troche bardziej optymalnie (bez uruchomienia posredniego shella,
ktory funkcja system() uzywa do interpretacji argumentow zanim uruchomi
wlasciwy program):
...
#include <unistd.h>
...
int status;
...
switch(pid=fork()) {
case 0:
execv("/usr/bin/vi",argvc,NULL);
perror("execv");
exit(1);
case -1:
perror("fork");
exit(1);
default:
while(wait(&status)!=pid)
;
fprintf(stderr,"program status=%i\n",WEXITSTATUS(status));
}
--
Andrzej Bialecki
---------------------+---------------------------------------------------------
abial@warman.org.pl | if(halt_per_mth > 0) { fetch("http://www.freebsd.org") }
Research & Academic | "Be open-minded, but don't let your brains to fall out."
Network in Poland | All of the above (and more) is just my personal opinion.
---------------------+---------------------------------------------------------
Technical Details
Message-ID:
<65ceai$dts@info.nask.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!korin.warman.org.pl!abialReferences:
<34797dd1.0@zeus.man.szczecin.pl> <34798497.2D22@ml.put.poznan.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!korin.warman.org.pl!abial From: abial@korin.warman.org.pl (Andrzej Bialecki) Newsgroups: pl.comp.lang.c Subject: Re: Jak to zrobic???? Date: 24 Nov 1997 17:42:42 GMT Organization: Public NewsServer at NASK N.O.C. Lines: 45 Message-ID: <65ceai$dts@info.nask.pl> References: <34797dd1.0@zeus.man.szczecin.pl> <34798497.2D22@ml.put.poznan.pl> NNTP-Posting-Host: korin.nask.waw.pl X-Newsreader: TIN [version 1.2 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit