Feature Requests item #1324176, was opened at 2005-10-11 21:46 Message generated for change (Comment added) made by loewis You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1324176&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Windows Group: None Status: Open Resolution: None Priority: 5 Submitted By: Vambola Kotkas (kotk) Assigned to: Nobody/Anonymous (nobody) Summary: fix for ms stdio tables Initial Comment: Hopefully its right tracker for such request. I am mainly C++ developer but recently it become desirable to embed python as python24.dll into my existing app to make some of features scriptable. I don't want it to have any visible UI or to deal with GUI or the like. However ms has made it so that each dll has its own rtl ioinfo table that is loaded at program start. In other words .. some other dll or exe itself cannot simply redirect python24.dll stdin stdout stderr runtime. It probably has to be done from within python for these redirections to really take effect. I think it is actually very simple to fix that dll problem on C level by making some callable thing into python24.dll that does nothing but fixes dlls ioinfo table to contain real stdio for the process. Example: #include <windows.h> #include <io.h> void Py_FixMSstdioPITA(void) { /*fix stdin*/ HANDLE hReal = GetStdHandle (STD_INPUT_HANDLE); HANDLE hKnown = _get_osfhandle(_fileno (stdin)); int Number; if (hReal != hKnown && hReal != INVALID_HANDLE_VALUE) { Number = _open_osfhandle (hReal, _O_BINARY|_O_RDONLY); _dup2(Number,_fileno(stdin)); } /*fix stdout*/ hReal = GetStdHandle (STD_OUTPUT_HANDLE); hKnown = _get_osfhandle(_fileno(stdout)); if (hReal != hKnown && hReal != INVALID_HANDLE_VALUE) { Number = _open_osfhandle (hReal, _O_BINARY|_O_WRONLY); _dup2(Number,_fileno(stdout)); } /*fix stderr*/ hReal = GetStdHandle (STD_ERROR_HANDLE); hKnown = _get_osfhandle(_fileno(stderr)); if (hReal != hKnown && hReal != INVALID_HANDLE_VALUE) { Number = _open_osfhandle (hReal, _O_BINARY|_O_WRONLY); _dup2(Number,_fileno(stderr)); } } I want just call it from outside after any io redirection done in my code ... so python has his stdio all right and done. If something like this is already implemented there in similar or some other way then sorry didnt find it. If its agains general python ideology of some sort then sorry didnt know of it. Let me know please. Best wishes, Vambola Kotkas ---------------------------------------------------------------------- >Comment By: Martin v. Löwis (loewis) Date: 2005-11-08 00:36 Message: Logged In: YES user_id=21627 I don't understand the remark "has its own rtl ioinfo table". ioinfo is a type - what table are you referring to? If you are talking about __pioinfo: this certainly isn't defined per DLL. Instead, each copy of the MS C runtime has one copy. Python (in 2.4) uses msvcr71.dll. So as long as you also link against msvcr71.dll, you can modify the CRT that Python uses without modifying python24.dll. IOW, you can use your function in your application, and be done. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1324176&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com