win10 createprocess等执行批处理窗口闪退

2016-10-26 C++

32位程序本来在win7 64位系统上运行没问题,后来系统升级到win10时,原先使用createprocess等执行的批处理程序启动不了

后来把程序编译成64位后就可以了!

通过测试,发现原来是win10系统上的32位cmd.exe启动不起来,而32位系统虽然是调用c:\windows\system32里面的cmd.exe,

实际上调用的是c:\windows\sysWow64里面的cmd.exe,具体可以查看如下网址解释:

http://www.cnblogs.com/hbccdf/p/dllchecktoolandsyswow64.html

当然如果要在32位系统调用system32里面的cmd.exe,微软也有提供接口实现!

Wow64DisableWow64FsRedirection:具体调用方式参考:

https://msdn.microsoft.com/zh-tw/library/aa365743(v=vs.85).aspx


标签: win10 createprocess 批处理

评论(0) 浏览(6637)

vs2008编译出错C2813 #import is not supported with /MP

2016-10-25 C++

用vs2008编译别人项目时候出错,报错码c2813  #import is not supported with /MP

上网找了下原因大致是import不支持并发编译;

具体错误解释https://msdn.microsoft.com/zh-cn/library/bb384890.aspx

解决办法:在项目属性的c/c++命令行加上额外参数/MP1 使用单处理器编译

标签: vs2008 C2813 MP

评论(0) 浏览(8172)

python yield 使用说明

2016-10-15 python

标签: python yield

评论(0) 浏览(3360)

python with 使用说明

2016-10-15 python

参考:http://effbot.org/zone/python-with-statement.htm

一旦知道with段用于解决什么问题,那使用with语法将会非常简单:

如下片段:

    set things up #打开一个文件或请求外部资源

    try :

        do something

    finally :

        tear things down #关闭文件或释放资源

    try-finally结构保证"tear things down"一直都会被执行,不管"do something"有没有完成


如果要经常使用这个结构,可以考虑使用如下结构:

    def controlled_execution(callback) :

        set things up

        try :

            callback(thing)

        finally :

            tear things down

    def my_fn(thing) :

        do something


    controlled_execution(my_fn)

但是看起来有点啰嗦, 也可以采用如下方式:

    def controlled_execution() :

        set things up

        try :

            yield thing

        finally :

            tear things down


    for thing in controlled_execution() :

        do something in thing

但你只要执行一次函数时,也要使用loop就有点奇怪了

python团队使用如下结构来替代:

    class controlled_execution :

        def __enter__(self) :

            set things up

            return thing

        def __exit__(self, type, value, traceback) :

            tear things down

    with controlled_execution() as thing :

        some code

当with执行时,python执行__enter__方法,返回值给thing,

然后执行some code, 不管some code执行成功与否,执行完调用__exit__方法;

如果要抑制异常抛出,可以使__exit__()返回True,如忽略TypeError:

    def __exit__(self, type, value, traceback) :

        return isinstance(value, TypeError)

打开一个文件,处理里面内容然后保证它被关闭,可以使用如下代码:

    with open("x.txt") as f :

        data = f.read()

        do something with data

    

标签: python with

评论(0) 浏览(2359)

OpenProcess 打开任务列表不存在进程返回200

2016-10-12 C++

通过OpenProcess判断进程存不存在时,

对于在进程管理器不存在的进程通过OpenProcess打开时返回不为NULL

原因是进程存在时open时没有关闭HANDLE

进程关闭后,虽然在进程管理器找不到该进程,

但是openprocess打开返回不为NULL

解决办法,保证每个openprocess后都对应closehandle

标签: VC OpenProcess

评论(0) 浏览(3472)

python 解决‘ascii‘ codec can‘t encode characters in position ordinal not in range(128)

2016-10-10 python

使用java 通过cmd调用python脚本时出现unicodeEncodeError

通过搜索说是读取文件默认是ascii而不是utf8导致的

在代码中加上如下几句即可

import sys

reload(sys)

sys.setdefaultencoding(‘utf8’)

标签: python

评论(0) 浏览(3199)

python dir_util copy_tree errno 9

2016-10-9 python

使用python2.7.10写脚本从一个文件夹复制文件到另一个文件夹时出错

错误原因在读取源文件时找不到文件描述

errno 9

但是通过python idle执行可以,后来把python更新到2.7.12版本就可以了

可能是2.7.10 bug吧

运行环境 windows 2008 64位 英文版

标签: python

评论(0) 浏览(3394)

Powered by EMLOG Copyright @ 深圳市炽旗科技 版权所有. 闽ICP备14012694号-2