Jump to content

Recommended Posts

Posted

Пишу на Си:

int i;

i = dup(fileno(stdout));

fprintf(stdout,"1\n");

stdout = reopen("/res","w",stdout);

fprintf(stdout,"2\n");

fflush(stdout);

execlp("ipchains","","-L");

fclose(stdout);

stdout = fdopen(i,"w");

fprintf(stdout,"3\n");

fprintf(stderr,"---stderrr---\n");

Результат:

(на экране)

1

(в файле)

2

[список цепочек]

И ВСЕ! Ни третьей трассироввочной пометки, ни вывода в stderr!

После execlp вывод как ножом отрезало! В чем я ошибся?

Posted

Потому что после execlp все остальное не будет работать.

При вызове execlp Ваш процесс заменяется другим - ipchains.

Если надо вызвать какую-то программу, а после нее продолжить исполнение - то тут либо библиотечная функция system() (самый простой вариант) либо - fork/exec/wait

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...