c/c++, mfc: Not passing open files / handles to a spawned process

技术标签: Visual-Studio-2008  MFC  spawn

In unix I know the routine: between fork() and exec() in the child I close everything except stdin/out/err, so that all the open ports or files are not passed to the program I want to run.

But how do I do this in windows? In my case I'm implementing a DLL in C/C++, and I need to close both some files I opened (indirectly via some objects) and the sockets opened by the Application that loaded the dll, so that these open file handles are not passed to the application I'm spawning. The app doesn't pass those handles to the DLL, as my code shouldn't need those...

So far the code simply calles _spawnl(_P_NOWAIT, "foo.exe", "foo.exe", "arg1", "arg2",NULL); Visual Studio 2008 if that matters.

谢谢你的帮助。

看答案

hmm - sorry to be guessing here a little, but are you sure spawnl in Windows passes the open file handles?

If so, maybe you want to look at CreateProcess, and StartupInfo - these allow finer control over what gets passed/inherited to the new process


智能推荐

项目部署时出现问题django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supporte

终端提示信息如下: django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supporte Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to...

Fatal error in launcher: Unable to create process using“”C:\Program Files (x86)\Python 出现这个错误的终极解决办法

Fatal error in launcher: Unable to create process using “”C:\Program Files (x86)\Python33\python.exe“ ”C:\Program Files (x86)\Python33\pip.exe“” 当在终端输入pip 命令出现 如上问题...

Error:Your project contains C++ files but it is not using a supported native build system

在编写JNI代码时遇到该问题,进过查阅资料,出现此错误的原因是项目中包含C++的文件,但是你的编译工具不支持,遇到该问题时首先想到build.gradle文件中是否配置相应的说明,配置如下: 然后进行编译看看是否成功,我的测试是成功了。然后还有相关配置,但是我认为这个配置好像在Android Studio2.3以后是不起什么作用的。就是在gradle.properties中配置一行代码。 这个方法...

Error: Your project contains C++ files but it is not using a supported native build system

 在appde build.gradle 中的 buildType中添加 以下这句代码: 示例如图:...

Android Studio:Your project contains C++ files but it is not using a supported native build system.

 Error: Your project contains C++ files but it is not using a supported native build system.   Consider using CMake or ndk-build integration. For more information, go to:    https:...

猜你喜欢

Error: Your project contains C++ files but it is not using a supported native build system.

最近在导入项目时出现这个错误: 解决办法在APP的build.gradle里添加这段代码:  ...

The server cannot or will not process the request due to something that is perceived to be a client

错误如下: 400错误,大致意思为:服务器无法或将不会处理该请求,因为某些内容被认为是客户端错误(例如,格式错误的请求语法、无效的请求消息框架或欺骗性的请求路由) 此类错误基本为类型转换错误,即在客户端获取到的值的类型与你加入数据库所需要的类型不一致。 如本人最近此错误是因为时间日期转换,在maven项目中配置的时间转换器未开启,所以出现这种情况着重检查一下数据类型。...

redis中的hash扩容渐进式rehash过程

背景: redis字典(hash表)当数据越来越多的时候,就会发生扩容,也就是rehash 对比:java中的hashmap,当数据数量达到阈值的时候(0.75),就会发生rehash,hash表长度变为原来的二倍,将原hash表数据全部重新计算hash地址,重新分配位置,达到rehash目的 redis中的hash表采用的是渐进式hash的方式: 1、redis字典(hash表)底层有...

不同系统下的回车\r和换行\n,及其历史

2019独角兽企业重金招聘Python工程师标准>>>      我们平时按下键盘上的‘回车键’,就能实现回车换行【我们在屏幕上所看到的就是光标移到了下一行的开头位置!!ps:不讨论软件实现的特殊功能,如word里的回车智能缩进】。因此对这个按键更准确说应该叫做‘回车换行键’ 就且将这种将光标移到下行开...

windows操作系统,python环境下django的自动安装

首先,在Windows操作系统下安装python,完成python环境的搭建。(我看有的博客需要配置环境变量,其实不必要,因为我们在安装的时候只要勾选如下图所示即可避免不必要的麻烦) 第二步,使用快捷键windows+R或者点击如下图所示,之后点击运行 在其中输入cmd即可进入dos命令。 第三步,输入以下命令 就会自动安装,等待安装完成即可。 第四步,检测django是否安装成功,如果出现如下图...

问答精选

How to get the sum of rows using a vector and the make the result in a column

I have a dataframe and i want to calculate the sum of variables present in a vector in every row and make the sum in other variable after i want the name of new variable created to be from the name of...

Call a custom class in zend framework

I have a very rough project that done partially in zend framework (not ZF2). The 'application', 'library' and 'public' folders are on the same root. Now i need to create a library 'Anil' in the 'libra...

Hide Some Of The Categories In Magento?

I want to hide some of the categories from magento home page. I have created some categories like New Arrivals, Special Offer Which I would like to show in some different way may be in left panel or r...

Reading an internal file in Android Studio

I am writing to an internal file in Android Studio The code lets me write lines of data split with commas. I am able to then go to another activity and read it all out at once. However I want to be ab...

Rails Acts_as_votable Gem Like/Unlike Buttons with Ajax

I'm new to Ruby On Rails, I used the acts_as_votable gem to create Like and Unlike Buttons to make Users like and unlike Posts but I can't make them change from Like to Unlike (and viceversa) and upda...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答