English 中文(简体)
页: 1 开放
原标题:pOpen with python
  • 时间:2011-11-22 20:59:04
  •  标签:
  • python
  • popen

这与我有关系。

我有一幅长篇的文字,在视窗平台上做了一些工作,以制作XML文件,下载一些图像,然后打电话给外部的青.应用,以制作使用Xml的录像,并拍摄出该笔文字的图像。

我向POPen提出的申请,应视其如何解释我通过的数据而恢复现状,即[成功]或[失败]。

如果我用我的代稿生成信息,然后用另一本书把奥塞罗尔应用程序单独称作,那么,它就做了一些出色的工作,我取得了成功,并制作了录像。

成功准则(请 ignore击测试版):

print ("running console app...")

cmd =  "C:/Program Files/PropertyVideos/propertyvideos.console.exe" -xml data/feed2820712.xml -mpeg -q normal 
print (cmd)
p = subprocess.Popen(cmd , stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.communicate()[0]
print ("
----
[" + output + "]
----
")

if output == "[success]":
    print "
HURRAHHHHH!!!!!!!"

print ("finished...")

但是,如果在文字末尾加上相同的代码,生成信息,以输入黄色应用,则该编码可操作约2秒和产出=[]。

Same 代码,在不同的文字结尾......

EDIT: Thanks to Dave, Dgrant and ThomasK it seems to be that the generate script is not closing the file as redirecting strerr to stdout shows:

Unhandled Exception: System.IO.IOException: The process cannot access the file  
C:videosdatafeed2820712.xml  because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I
nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o
ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

However I AM closing the file: Extract from the generation script:

    xmlfileObj.write( </FeedSettings>
 ) # write the last line
    xmlfileObj.close

    # sleep to allow files to close
    time.sleep(10)

    # NOW GENERATE THE VIDEO
    print ("initialising video...")

    cmd =  "C:/Program Files/PropertyVideos/propertyvideos.console.exe" -xml data/feed2820712.xml -mpeg -q normal 
    print (cmd)
    p = subprocess.Popen(cmd , stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output = p.communicate()[0]
    print ("
----
[" + output + "]
----
")

    if output == "[success]":
        print "
HURRAHHHHH!!!!!!!"

    print ("finished...")   

希望得到任何帮助。

问题回答

您不再结案。 你的法典说:

xmlfileObj.close

when it should be

xmlfileObj.close()

<><>Edit>: 仅澄清——代码xmlfileObj.close是一种有效的假冒表述,可检索<代码>所载明的参考(或类似档案)物体。 因为它是一种有效的陈词典,它完全是法律,但没有任何副作用。 具体来说,它没有实际使用<代码>close()方法的效果。 你们需要列入公开和接近的方括号。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签