python操作windows软件,使用Python运行Windows命令

Searching this forum I found an example of running Unix commands from Python;I wonder if there is a way to get the output of windows commands on a string using Python.I believe command line functionality is built in into Python only for *nix environment.Is there''s a windows solution?

Thanks in advance;

Miago.

解决方案Searching this forum I found an example of running Unix commands from Python;I wonder if there is a way to get the output of windows commands on a string using Python.Thanks in advance;

Miago.

It sort of depends on which Window app you are trying to interface to. Most Microsoft products and some third party products are COM (Common Object Model) aware. With the PythonWin package, you can send commands to these apps as if you were using a VB script. If your python program has a full GU interface you could Select the text that you want, then Copy using the VB commands then get the clipboard contents in your program. Or you might be able to SaveAs text and read the resulting file. I''ve seen an example that copied text from MS Word and pasted it to a web page. The possibilities are endless, but I''m not very familiar with PythonWin. There are some on this forum who are, though. I use wxPython so all my Python programs have almost complete access to Windows'' features like the clipboard. PythonWin is another way to do this, but you pretty much have to know the Windows API first.

Hope this is useful to you,

Barton

Searching this forum I found an example of running Unix commands from Python;I wonder if there is a way to get the output of windows commands on a string using Python.Thanks in advance;

Miago.

You may be able to do this by reassigning sys.stdout.

Searching this forum I found an example of running Unix commands from Python;I wonder if there is a way to get the output of windows commands on a string using Python.Thanks in advance;

Miago.

Good point, motoma. I was thinking of Windows apps, but there may be a way to redirect the output of a Windows command that is designed to echo text to the command-line. Anybody have any experience with this?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值