4

サブプロセスを起動するアプリケーションがあります。サブプロセスは、操作するファイルをstdinから読み取ります。一部の操作では、操作するファイルをどう処理するかに関する情報を含む入力ファイルが必要です。これを「制御ファイル」と呼びましょう。制御ファイルの名前もstdinから読み取られます。親アプリケーションは一時ファイルを制御ファイルとして使用できますが、実際のディスクバックアップファイルは避けたいと思います。

On Linux, this is simple: I can create a Unix pipe, fork, close the respective ends of the pipe before starting the subprocess, and use /dev/fd/3 (or whatever the file descriptor is) as control file name, and then write the control data to the pipe in the parent application. Alternatively, I could use a named pipe in /tmp (or whatever).

How could I achieve a similar thing on Windows? Could the strange "named pipes" Windows offers be used for this, that is, can they be read from by the usual C library fread() function? If yes, what file name do I use to access them? Or is there a better way than using named pipes?

(The subprocess is the exiftool command-line utility run in batch mode, so I don't have control over it. The parent application is written in Python.)

4

2 に答える 2

0

アップデート:

@Harry Johnston は、私があなたの質問を誤解していると指摘しています。サブプロセスを変更したくないのです。その場合は、呼び出しを試みて、fromのメンバーをCreateProcess埋めることができます。hStdInputSTARTUPINFOHANDLECreateNamedPipe

以前の回答:

一般に、Windows CRT (C ランタイム、またはlibcUnix で言えば " ") は奇妙な獣です。これは、C 標準ライブラリの非常に「最低限の」シムであり、いくつかの余分なものが投入されており、あまりよく維持されておらず、あまり公開されていません。 Windows でできること。Windows ソフトウェアを C で記述する最も自然な方法は、Win32 API です。それは言った:

Windows が提供する奇妙な「名前付きパイプ」をこれに使用できますか。つまり、通常の C ライブラリ fread() 関数で読み取ることができますか?

_open_osfhandleはい、最初のパラメーターを にすることができる でそれを行うことができると思いますHANDLE。これは、Windows CRT の Unix ファイル記述子の奇妙なあざけりである整数を与えます。FILE*その後、 withを取得できます_fdopen

はいの場合、それらにアクセスするためにどのファイル名を使用しますか?

衝突しないランダムなものを生成しようとすることができると思います。アプリケーションの名前を前に付けて、プロセス ID と現在の時刻を組み合わせてください。それは私がそこに捨てているものです。

または、名前付きパイプを使用するよりも良い方法はありますか?

ファミリ内でソケットを使用できますが、AF_UNIX最終的にはかなり似ています...

于 2012-08-01T20:00:20.313 に答える