Article View: pl.comp.os.linux.programowanie
Article #72819Re: Jaka funkcja jak system() ale z podawaniem katalogu roboczego?
From: Borneq
Date: Wed, 01 Feb 2017 16:16
Date: Wed, 01 Feb 2017 16:16
30 lines
1669 bytes
1669 bytes
W dniu 01.02.2017 o 16:59, Adam Wysocki pisze:
> chdir
> exec*
zrobiłem:
dwa pierwsze parametry do ścieżka do shella a następny "-c"
void execSystem(string command, string workDir)
{
const char *defShell="/bin/bash";
const char* shellPath;
shellPath = getenv ("SHELL");
if (shellPath==NULL)
shellPath = defShell;
__pid_t pid = fork();
int status;
switch(pid)
{
case -1: exit(-1);
case 0:
{
chdir(workDir.c_str());
execlp(shellPath,shellPath,"-c" ,command.c_str(),NULL);
}
break;
default:
{
waitpid(pid,&status,WUNTRACED);
}
}
}
Technical Details
Message-ID:
<o6t1kc$uk2$1@node1.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<o6sibv$f31$2@node1.news.atman.pl> <2eTd7vlduI38hNv8%gof@news.chmurka.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Borneq <borneq@antyspam.hidden.pl> Newsgroups: pl.comp.os.linux.programowanie Subject: Re: Jaka funkcja jak system() ale z podawaniem katalogu roboczego? Date: Wed, 1 Feb 2017 17:16:12 +0100 Organization: ATMAN - ATM S.A. Lines: 33 Message-ID: <o6t1kc$uk2$1@node1.news.atman.pl> References: <o6sibv$f31$2@node1.news.atman.pl> <2eTd7vlduI38hNv8%gof@news.chmurka.net> NNTP-Posting-Host: 91.239.205.105 Mime-Version: 1.0 X-Trace: node1.news.atman.pl 1485965772 31362 91.239.205.105 (1 Feb 2017 16:16:12 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Wed, 1 Feb 2017 16:16:12 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 In-Reply-To: <2eTd7vlduI38hNv8%gof@news.chmurka.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit