मुझे लगता है कि इस काम को करने के लिए आपको एक देशी डीएलएल बनाने की आवश्यकता होगी जो परेशानी डीएलएल के समान सी ++ रनटाइम से लिंक हो। फिर आपको stdout को पुनर्निर्देशित करने के लिए freopen
का उपयोग करने की आवश्यकता होगी। freopen: reverting back to original stream
सी ++ कोड इस प्रकार दिखाई देगा: इस कोड के लिए मेरे स्रोत इस जवाब है
#include <io.h>
__declspec(dllexport) void RedirectStdOutputToNul(int *fd, fpos_t *pos)
{
fflush(stdout);
fgetpos(stdout, pos);
*fd = _dup(fileno(stdout));
freopen("NUL", "w", stdout);
}
__declspec(dllexport) void RestoreStdOutput(int fd, fpos_t pos)
{
fflush(stdout);
_dup2(fd, fileno(stdout));
close(fd);
clearerr(stdout);
fsetpos(stdout, &pos);
}
आप पी/आह्वान कर सकते हैं कि आपके कोड से इस तरह:
[DllImport(dllname, CallingConvention = CallingConvention.Cdecl)]
static extern void RedirectStdOutputToNul(out int fd, out long pos);
[DllImport(dllname, CallingConvention = CallingConvention.Cdecl)]
static extern void RestoreStdOutput(int fd, long pos);
और तुम इसे इस तरह कॉल कर सकते हैं:
int fd;
long pos;
RedirectStdOutputToNul(out fd, out pos);
print("boo");
RestoreStdOutput(fd, pos);
print("yah");
यह सब एक गतिशील से जुड़े डीएलएल पर निर्भर करता है एमएसवीसी रनटाइम और आप उस कोड को लिखने में सक्षम हैं जो समान लिंक करता है।
स्रोत
2014-04-21 18:50:47
क्या आप अपना कोड बदल सकते हैं ताकि यह सी ++ डीएलएल को एक अलग प्रक्रिया में कॉल कर सके? यदि ऐसा है तो आप 'ProcessWindowStyle.Hidden' विकल्प' के साथ अलग प्रक्रिया लॉन्च कर सकते हैं। यह वही नहीं हो सकता है जो आप खोज रहे हैं, लेकिन यह काम करेगा। – shf301