windows命令查看软件安装情况

2017年4月09日 14:07

在windows上,可以通过控制面板,查看软件安装情况。那么除此之外还有其它方法吗?
 
  • powershell命令
PS C:\Users\wyq> Get-WmiObject -class Win32_Product |Select-Object -Property name,version

name                                                                                                 version
----                                                                                                 -------
Microsoft Visual C++ Compiler Package for Python 2.7                                                 9.0.1.30729
Microsoft .NET Framework 4.5.1 Multi-Targeting Pack                                                  4.5.50932
Microsoft Visual C++  x64-x86 Cross Compilers - CHS Resources                                        12.0.21005
Microsoft SQL Server 2012 T-SQL Language Service                                                     11.1.3000.0
....
 

Tags: powershell windows
评论(1) 阅读(2371)

windows上subprocess.Popen的参数close_fds=True与管道不能共存

2017年3月21日 21:46

  • 运行命令
subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
  • 出现错误
ValueError: close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderr
 
  • 原因
在windows上subprocess.Popen的参数close_fds=True与stdin/stdout/stderr不能共存
  1. close_fds=True表示子进程将不会继承父进程的输入、输出、错误管道。
  2. windows上不能将close_fds设置为True同时重定向子进程的标准输入、输出与错误(stdin, stdout, stderr)
 

评论(137) 阅读(19113)

hyper-v查看虚拟机启动顺序

2017年2月02日 21:56

PS C:\> get-vm 虚拟机名称 |get-vmbios
VMName            StartupOrder                            NumLockEnabled
------            ------------                            --------------
虚拟机名称        {CD, IDE, Floppy, LegacyNetworkAdapter} False

Tags: powershell
评论(40) 阅读(3512)

powershell如何ping

2017年2月02日 21:47

PS C:\Users\xxx> Test-NetConnection 192.168.1.13
ComputerName           : 192.168.1.13
RemoteAddress          : 192.168.1.13
InterfaceAlias         : 以太网
SourceAddress          : 192.168.1.100
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms



PS C:\Users\xxx> Test-NetConnection 192.168.1.13 -Port 8000
ComputerName           : 192.168.1.13
RemoteAddress          : 192.168.1.13
RemotePort             : 2179
InterfaceAlias         : 以太网
SourceAddress          : 192.168.1.100
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded       : True

 

Tags: powershell
评论(38) 阅读(2293)

python多行字符拼接使用小括号

2017年2月02日 21:33

* 多行字符串拼接使用小括号
 
s = ('select *'
     'from atable'
     'where id=888')
print s, type(s)

#输出
select *from atablewhere id=888 <type 'str'>
 
* python遇到未闭合的小括号,自动将多行拼接为一行,相比三个引号和换行符,这种方式不会把换行符、前导空格当作字符。
 

Tags: 拼接 字符
评论(1) 阅读(2204)

powershell递归删除文件

2016年9月26日 20:50

  • 在powershell上执行
get-childitem * -include *.pyc -recurse |remove-item
  • 或者使用别名
ls * -include *.pyc -recurse |rm

 

Tags: windows
评论(42) 阅读(4341)

32位python的bug:os.system返回码一直为0

2016年9月26日 20:33

32位python在windows上调用命令行(os.system或subprocess.Popen)。执行后,如果返回码太大,python取得的返回值也是0。此时无法判断执行成功还是失败,这个是32位python的bug。
 
以时间同步命令w32tm位例子

在cmd上执行

C:\WINDOWS\system32>w32tm /resync
发生下列错误: 服务尚未启动。 (0x80070426)

C:\WINDOWS\system32>echo %errorlevel%
-2147023834

在64位python上执行

>>> os.system("w32tm /resync")
发生下列错误: 服务尚未启动。 (0x80070426)
-2147023834

在32位python上执行

>>> os.system("w32tm /resync")
发生下列错误: 服务尚未启动。 (0x80070426)
0
注意:此时命令执行错误的返回码也是0。
通常成功返回码才是0,这里执行错误,返回码却是也0。当要判断执行成功还失败时,这里便是个坑。
  • os.system文档
https://docs.python.org/2/library/os.html
 

Tags: popen system python
评论(54) 阅读(3402)

cmd切换为administrator用户

2016年9月26日 19:46

runas /noprofile /user:Administrator cmd
  • runas         允许用户用其它权限运行指定的工具和程序
  • /noprofile    指定不应该加载用户的配置文件。
  • /user:UserAccountName  指定在其下运行程序的用户帐户的名称
 

Tags: windows DOS runas
评论(1) 阅读(6222)

git status 显示乱码

2016年5月27日 05:22

  • 查看修改历史,出现下面"乱码"
修改:     "data/python\345\255\246\344\271\240\350\265\204\346\226\231.wiki"
  • 设置
git config --global core.quotepath false
显示正常
 

评论(35) 阅读(3745)

apscheduler提示maximum错误

2015年12月15日 20:59

起因

在tornado中用apscheduler实现计划任务,出现错误提示
 
2015-12-04 19:10:22,227 - apscheduler.scheduler - WARNING - Execution of job "TaskHandle.progress_job (trigger: date[2015-12-04 19:10:22 CST], next run at: 2015-12-04 19:10:22 CST)" skipped: maximum number of running instances reached (1)

分析

缺乏资料,所以根据提示,分析apscheduler源码
  • 记录异常位置
在源码目录下,搜索关键字maxinum,找到记录异常的位置
#apscheduler/schedulers/base.py
if run_times:
    try:
        executor.submit_job(job, run_times)
    except MaxInstancesReachedError:
        self._logger.warning(
            'Execution of job "%s" skipped: maximum number of running instances reached (%d)',
            job, job.max_instances)
    except:
        self._logger.exception('Error submitting job "%s" to executor "%s"', job, job.executor)
  • 异常抛出位置
 
继续看submit_job函数,找到异常抛出位置
#apscheduler/executors/base.py
def submit_job(self, job, run_times):
    """
    Submits job for execution.

    :param Job job: job to execute
    :param list[datetime] run_times: list of datetimes specifying when the job should have been run
    :raises MaxInstancesReachedError: if the maximum number of allowed instances for this job has been reached
    """

    assert self._lock is not None, 'This executor has not been started yet'
    with self._lock:
        if self._instances[job.id] >= job.max_instances:
            raise MaxInstancesReachedError(job)

        self._do_submit_job(job, run_times)
        self._instances[job.id] += 1
  • _instances变量作用
在submit_job(提交任务)时加1,在_run_job_success(任务运行成功)时减1。 当self._instances[job.id]大于job.max_instances抛出异常。
max_instances默认值为1,它表示id相同的任务实例数。

解决

通过设置max_instances参数
sched.add_job(child_job, max_instances=10, trigger=DateTrigger(), id="123")

重现脚本

import time
import tornado.ioloop
from apscheduler.triggers.date import DateTrigger
from apscheduler.schedulers.tornado import TornadoScheduler

sched = TornadoScheduler()

def child_job():
    print "start"
    time.sleep(60)
    print "end"

def main_job():
    sched.add_job(child_job, trigger=DateTrigger(), id="123")

sched.add_job(main_job, 'interval', seconds=5)

sched.start()
tornado.ioloop.IOLoop.instance().start()
  • 输出
job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1
job_id: 123, instances: 0, max_instances: 1
start
job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1
job_id: 123, instances: 1, max_instances: 1
WARNING:apscheduler.scheduler:Execution of job "child_job (trigger: date[2015-12-07 15:27:11 CST], next run at: 2015-12-07 15:27:11 CST)" skipped: maximum number of running instances reached (1)
job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1
 

Tags: tornado;apscheduler
评论(11) 阅读(11630)