LINUX.ORG.RU

импортировать сишный popen

 , ,


0

1

Здравствуйте, я хочу использовать сишный popen в Хаскеле. У меня два вопроса: 1) почему при компиляции такого кода:

{-# INCLUDE <unistd.h> #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Popen() where

import Foreign.C.Types
import Foreign.C.String
import IO

foreign import stdcall unsafe "popen"  c_popen  :: CString -> CString -> IO (Ptr CFile)
foreign import stdcall unsafe "pclose" c_pclose :: Ptr CFile -> IO()

я получаю:

[1 of 1] Compiling Popen            ( /home/aswed/new.hs, interpreted )
ghc: panic! (the 'impossible' happened)
  (GHC version 6.12.1 for i386-unknown-linux):
	convToABI: convention not supported

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
Debian-specific note: please remove old .hi files and try again.
For details, see /usr/share/doc/ghc6/README.Debian
2) Как конвертировать CFile в Handle и обратно?

★★★★★

Ответ на: комментарий от anonymous

Нет, я просто так тут топик создал, мне делать нечего в субботу вечером. Уверен.

Aswed ★★★★★
() автор топика
Ответ на: комментарий от Begemoth

Да, это то, что мне нужно, спасибо

Aswed ★★★★★
() автор топика
Ответ на: комментарий от Begemoth

Begemot, что я не так делаю:

(mhIn,mhOut,merr,_) <- createProcess (shell "ls")
print (mhIn,mhOut,merr)
терминал:
(Nothing,Nothing,Nothing)
aswed@debian:~/Coding/Haskell/Proc$ new.c	  reciver     reciver.hs  sender     sender.hs
new.c.ex  reciver.hi  reciver.o   sender.hi  sender.o
т.е. потоки дочернего процесса направлены на экран, и обратится к процессу нельзя. Такая проблема возникает не только с ls.

Aswed ★★★★★
() автор топика
Ответ на: комментарий от Begemoth

Все, разобрался, еще раз спасибо.

Aswed ★★★★★
() автор топика

foreign import stdcall ...

ghc: panic! (the 'impossible' happened)
(GHC version 6.12.1 for i386-unknown-linux):
convToABI: convention not supported

1. Вам нужен не stdcall, а cdecl.
2. ghc-6.12.1 имеет тонну багов FFI. Лучше использовать как минимум 6.12.4 (а еще лучше 7.x)
3. Про System.* уже сказали.

sf ★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.