Windows上的批处理命令 [英] Batch commands on Windows

查看:81
本文介绍了Windows上的批处理命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,在阅读了一些关于os.system的消息,并查看popen

的东西并尝试了一下之后,我仍然没有办法保留命令

窗口打开几个命令(在Windows 2000 / XP上),同时在命令窗口中看到

正常输出。我想要做的就是做一个批处理文件

,但我想实际上有函数和关联数组,而且所有这些都是python的其他细节。


与此有什么关系?我认为Python最初是一个脚本

语言。这似乎是脚本语言应该做的最基本的事情。我只想列出命令,而不是处理

捕获输出并重定向它以及所有这些。这不仅仅是因为

我太懒了,这是因为我的大多数同事都不知道Python和我

想要的使过渡更容易,并在其上出售。这似乎是一个巨大的不足之处。有没有人知道是否可以这样做?


如果没有,这是perl的一个点,*喘气* :)我们_were_使用,但

我反对的原因是我不想进入。


我注意到这种非常好的软件缺乏的趋势

一些明显的区域。 Python在很多方面给我带来了惊喜,但是每次都经常遇到这样的事情,这是非常令人失望的。并且

是的我已经阅读了PEP 324,但它似乎没有提到像

这样的东西。另一个例子是Perforce,它绝对是99%b / b
的东西,但是你遇到了一些明显的漏洞。大多数软件只是

平庸。


谢谢,

MB

解决方案

>所以,在阅读了一些关于os.system的消息,并查看popen

的东西并尝试了一下之后,我仍然没有找到一种方法来保持一个命令窗口打开几个命令(在Windows 2000 / XP上),同时在命令窗口中看到
正常输出。我想要做的就是做批处理文件
,但我想实际拥有函数和关联数组以及所有其他的python的细节。



问:如何让python运行这些其他东西,并保持窗口

打开以便我可以看到它们的输出?

答:确保使用Python的控制台版本运行脚本
(python.exe,NOT pythonw.exe):


#insert你的脚本正文


raw_input(按输入继续......);

#甚至

#os.system(''pause'');

问:我正在运行非控制台版本的Python,我如何捕获

输出我的脚本以便我之后可以用它做什么?


A:明天我会回答这个问题,现在已经很晚了。


- Josiah


On Fri,2004-01-23 at 00:56,Moosebumps写道:那么,在阅读了一些关于os.system的消息,并查看popen
的东西并尝试了一下之后,我仍然没有找到一种方法来保持命令
窗口打开几个命令(在Windows 2000 / XP上),同时在命令窗口中看到
正常输出。我想要做的就是做批处理文件
,但我想实际拥有函数和关联数组以及所有其他的python的细节。



1.打开文件whatever.py,把它放进去:


print" Hello world"


2。打开cmd.exe,导航到whatever.py所在的位置并输入:


whatever.py


会发生什么?
< br $>
// m


ps这可能是我误解了你的问题,因为在脸上

,因为我理解你的问题,你说的是一个明显的

Python中的漏洞是Python的一个方面我每天都毫不费力地使用。


Moosebumps写道:

所以,在阅读了一些关于os.system的消息后,看着popen
的东西并尝试了一下,我仍然没有找到一种方法来保持命令窗口打开几个命令(在Windows 2000 / XP上),同时看到
命令窗口中的正常输出。我想要做的就是做批处理文件
,但我想实际上有函数和关联数组以及所有其他的python的细节。


您能举例说明您的意思,在Perl中以及您希望的内容是什么?
可以在Python中运行?我不太明白你在尝试做什么是什么。

这是什么交易?我认为Python最初是一种脚本语言。这似乎是脚本语言应该做的最基本的事情。



Dunno,虽然MS-DOS shell脚本肯定是脚本的一小部分

一般。也许有一个具体的例子,有人可以给你一个

手。


-Dave


So, after reading some messages about os.system, and looking at the popen
stuff and trying it a bit, I still have not found a way to keep a command
window open for several commands (on Windows 2000/XP), while seeing the
normal output in a command window. All I want to do is do what a batch file
does, but I want to actually have functions and associative arrays and all
the other niceties of python.

What''s the deal with that? I thought Python started out as a scripting
language. And that seems like the most basic thing that a scripting
language should do. I just want to list the commands, not deal with
capturing the output and redirecting it and all that. It''s not just because
I''m too lazy, it''s because most of my co-workers don''t know Python and I
want to make the transition easier and sell them on it. This seems like an
enormous deficiency. Does anyone know if this can be done?

If not, that''s a point for perl, *gasp* : ) Which we _were_ using, but
which I object to for reasons I won''t go into.

I have noticed this tendency for really good software to be deficient in
some obvious area. Python has amazed me in many respects, but every so
often I encounter something like this which is pretty disappointing. And
yes I have read PEP 324, but it doesn''t seem to make mention anything like
this. Another example is Perforce, which is absolutely outstanding for 99%
of things, but then you encounter some glaring hole. Most software is just
mediocre all around.

thanks,
MB


解决方案

> So, after reading some messages about os.system, and looking at the popen

stuff and trying it a bit, I still have not found a way to keep a command
window open for several commands (on Windows 2000/XP), while seeing the
normal output in a command window. All I want to do is do what a batch file
does, but I want to actually have functions and associative arrays and all
the other niceties of python.



Q: "How do I get python to run these other things, and keep the window
open so that I can see their output?"

A: Making sure to run your script with the console version of Python
(python.exe, NOT pythonw.exe):

#insert the body of your script here

raw_input("press enter to continue...");
# or even
#os.system(''pause'');
Q: "I''m running the non-console version of Python, how do I capture the
output of my scripts so that I can do something with it afterwards?"

A: I''ll answer this one tomorrow, it is getting late.

- Josiah


On Fri, 2004-01-23 at 00:56, Moosebumps wrote:

So, after reading some messages about os.system, and looking at the popen
stuff and trying it a bit, I still have not found a way to keep a command
window open for several commands (on Windows 2000/XP), while seeing the
normal output in a command window. All I want to do is do what a batch file
does, but I want to actually have functions and associative arrays and all
the other niceties of python.



1. Open file whatever.py, put this in it:

print "Hello world"

2. Open cmd.exe, navigate to where whatever.py is and type:

whatever.py

What happens?

// m

p.s. It''s likely I''ve misunderstood your question because on the face
of it, as I understand your question, what you''re saying is a glaring
hole in Python are aspects of Python I use effortlessly every day.


Moosebumps wrote:

So, after reading some messages about os.system, and looking at the popen
stuff and trying it a bit, I still have not found a way to keep a command
window open for several commands (on Windows 2000/XP), while seeing the
normal output in a command window. All I want to do is do what a batch file
does, but I want to actually have functions and associative arrays and all
the other niceties of python.
Can you give an example of what you mean, in Perl as well as what you hoped
would work in Python? I couldn''t quite understand what it is that you''re trying
to do.
What''s the deal with that? I thought Python started out as a scripting
language. And that seems like the most basic thing that a scripting
language should do.



Dunno, although MS-DOS shell scripting is certainly a small subset of scripting
in general. Maybe with a concrete example somebody will be able to give you a
hand.

-Dave


这篇关于Windows上的批处理命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆