a******k 发帖数: 1190 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: aablackk (black), 信区: Programming
标 题: [请教]文件输入
发信站: BBS 未名空间站 (Fri May 29 16:20:42 2009)
我需要在一个perl程序里面调用一个可执行文件
这个可执行文件使用数据文件作为输入
我有数据,
但是因为我不想把这些数据写到文件里面,再使用文件进行输入,
而想直接把这些数据传递给这个可执行文件
请问有没有什么办法? |
m*********g 发帖数: 273 | 2 if data.dat is your data and exe is your executable file,
then in perl `exe data.da`. Is this your problem? |
a******k 发帖数: 1190 | 3 no, data is generated on the fly,
i do not want to write them onto hard disk as data.dat
and want to supply them directly to exe |
m*********g 发帖数: 273 | 4 Can you change exe?
【在 a******k 的大作中提到】 : no, data is generated on the fly, : i do not want to write them onto hard disk as data.dat : and want to supply them directly to exe
|
a******k 发帖数: 1190 | 5 no
【在 m*********g 的大作中提到】 : Can you change exe?
|
R****a 发帖数: 199 | 6 Can you take something like the following:
yourownexecutable data1 data2 data3 ....
I guess that is not a good solution for you if you have too many data items.
But this does satisfy your request.
【在 a******k 的大作中提到】 : no, data is generated on the fly, : i do not want to write them onto hard disk as data.dat : and want to supply them directly to exe
|
m**********g 发帖数: 434 | 7 questions:
1) can you make a c file/header to access that data file?
2) can you use perl to run that c file/header?
【在 a******k 的大作中提到】 : no
|
w********e 发帖数: 557 | 8 If exe can't changed then it is hard. Maybe you can use pipe to pass the
results to exe.
If exe can be changed, you can make exe wait for the results. |
a******k 发帖数: 1190 | 9 thanks, i realised that maybe i need my own exe
items.
【在 R****a 的大作中提到】 : Can you take something like the following: : yourownexecutable data1 data2 data3 .... : I guess that is not a good solution for you if you have too many data items. : But this does satisfy your request.
|
a******k 发帖数: 1190 | 10 there is no data file
data generated on the fly
i just do not want to put data into a file
【在 m**********g 的大作中提到】 : questions: : 1) can you make a c file/header to access that data file? : 2) can you use perl to run that c file/header?
|
a******k 发帖数: 1190 | 11 i was thinking piping, but no idea
probably i should program my own exe
【在 w********e 的大作中提到】 : If exe can't changed then it is hard. Maybe you can use pipe to pass the : results to exe. : If exe can be changed, you can make exe wait for the results.
|
p*****s 发帖数: 344 | 12 it all depends what ur exe read from.
if it takes a command option as filename and then open a file descriptor.
I am thinking maybe the parent process can overwrite the variable that
saves the fd. so that it can read from pipe.
【在 a******k 的大作中提到】 : i was thinking piping, but no idea : probably i should program my own exe
|
a******k 发帖数: 1190 | 13 yes, it takes a command option to read file, like:
exe -i file1 -j file2 -other options
is it possible to call it without file in perl?
【在 p*****s 的大作中提到】 : it all depends what ur exe read from. : if it takes a command option as filename and then open a file descriptor. : I am thinking maybe the parent process can overwrite the variable that : saves the fd. so that it can read from pipe.
|
p*****s 发帖数: 344 | 14 just some thoughts, never tried myself
1. you call "exe with -i file1 -j file2 ..." first. Assume the return
process id is , ls /proc//fd/
you should file some fd nums (
2. by default /proc//1, 2, 3 are your pipe fd
3. use gdb attach to the process
4. use dup2(,) to swap fd so that your exe can read
from pipe
【在 a******k 的大作中提到】 : yes, it takes a command option to read file, like: : exe -i file1 -j file2 -other options : is it possible to call it without file in perl?
|