如何从另一个python脚本运行一个python脚本并获取另一个python 3.4的输出?

时间:2018-11-03 02:30:59

标签: multithreading terminal subprocess python-3.4 gpsd

我有一段代码可以从USB GPS接收器获取GPS坐标。并且此代码使用线程,并且在导入到主文件中的python文件中不起作用(由于程序的组织方式,我不想将其直接放入主文件中)或类似python-3.4中的内容运行另一个python文件,并打印出我正在Subprocess中运行的脚本的全部输出。我看了几百个例子,所有例子都以失败告终,其中一些抛出了错误:

lubnaRef.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        //These are all of your children.
        Map<String, Object> lubna = (Map<String, Object>) dataSnapshot.getValue();


        for (String childKey: lubna.keySet()) {
            //childKey is your "-LQka.. and so on"
            //Your current object holds all the variables in your picture.
            Map<String, Object> currentLubnaObject = (Map<String, Object>) lubna.get(childKey);

            //You can access each variable like so: String variableName = (String) currentLubnaObject.get("INSERT_VARIABLE_HERE"); //data, description, taskid, time, title
        }
   }

   @Override
   public void onCancelled(DatabaseError databaseError) {

   }
});

有些人完全不打印任何内容,而有些人则抛出错误

"Errno [2] no such file or directory".

有人说:

"buffsize has to be an int"

我无法列出我尝试过的所有代码示例,因为从字面上看,这可能需要一整天的时间。但是我以多种方式尝试了Subprocess,包括:

SP.Popen,SP.call,SP.check_output 以及所有OS变体以及在子进程中使用:Shell = True,stdout,stderr,.PIPE,communication()等。我还尝试指定程序所在的目录,但无济于事。

以下是一些我尝试过的例子,这些例子不起作用:

 subprocess.CalledProcessError: Command 'revGeoCode.py' returned non-zero exit status 127 

output = subprocess.check_output("python3 revGeoCode.py", shell=True)
print(output)

output = subprocess.check_output("revGeoCode.py", shell=True)
print(output)

所需的输出:     任何发生或打印在revGeoCode.py中的内容,

他们是使用子进程在后台运行python文件并打印出python文件打印出的所有内容的一种方式,就像使用终端一样?

感谢您提供的任何帮助!

0 个答案:

没有答案
相关问题