Printing Popen Output Using Windows 7


 
Thread Tools Search this Thread
Top Forums Programming Printing Popen Output Using Windows 7
# 1  
Old 11-04-2015
Printing Popen Output Using Windows 7

Hi Guys,

I am new to python and I am trying to print ouput of Popen on my text screen (tkinter gui).

I was able to make it work on Linux with this code:

Linux: Working

Code:
def PrintSomething2():
	outputdata = commands.getstatusoutput("sudo fping -f host.list")
	for i in outputdata:
		print i
	sp.call(["rm", "host.list"])

However, I am trying to do the same for a windows machine but it is not working:

Windows: NOT Working

Code:
import subprocess as sp
from subprocess import Popen
import sys
import commands

def PrintSomething2():
	outputdata = Popen("scanping.bat")
	for i in outputdata:
		print i
	deletefile = Popen("DEL", "sites.txt")

Note: It is printing in my terminal though:

Image

Let me know if you have any tips. Thanks in advanced!
# 2  
Old 11-06-2015
Code:
deletefile = Popen(["del", "sites.txt"], shell=True, stdout=subprocess.PIPE)

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 11-06-2015
Quote:
Originally Posted by balajesuri
Code:
deletefile = Popen(["del", "sites.txt"], shell=True, stdout=subprocess.PIPE)

This one worked in deleting the file after the script executes! Thank you!

However, I am still not getting the ouput in the CLI to print in my screen.

Do you have a good method of printing the output of:

Code:
def PrintSomething2():
    outputdata = Popen("scanping.bat", cwd=r"C:\Users\jbantay\OneDrive\Python")
    print outputdata
    deletefile = Popen(["del", "sites.txt"], shell=True, stdout=sp.PIPE)

Because the error I am getting is:

Image

Please take note that this code is working when I am using a linux machine:

Code:
def PrintSomething2():
	outputdata = commands.getstatusoutput("sudo fping -f host.list")
	for i in outputdata:
		print i
	sp.call(["rm", "host.list"])

---------- Post updated at 03:52 AM ---------- Previous update was at 03:46 AM ----------

This is the entire code of it:

https://docs.google.com/document/d/1...h8R0ySbZI/edit

Thanks!

---------- Post updated at 04:13 AM ---------- Previous update was at 03:52 AM ----------

Solved it by using code below! Smilie

Code:
def PrintSomething2():
    outputdata = sp.Popen(["scanping.bat"], stdout=sp.PIPE).communicate()[0]
    print outputdata
    deletefile = Popen(["del", "sites.txt"], shell=True, stdout=sp.PIPE)

---------- Post updated at 04:15 AM ---------- Previous update was at 04:13 AM ----------

Here is the output printing in Tkinter:

Image
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

2. SCO

Printing to Windows 7 using Samba 2.0.3 via VPN connection to SCO 3.2v5.0.6

I would like to know if anyone has a way to PRINT TO a printer attached to a Windows 7 PC, from SCO, while logged in via a VPN connection. I am able to attach to a Samba share on the SCO server for files while attached to the VPN, so I know my Samba is workling - but my print jobs return: ... (2 Replies)
Discussion started by: tbb999
2 Replies

3. AIX

Printing from AIX 5.0 to windows

Dear All, I just want to know how we can print a report from unix server to that printer which has installed on windows. As from UNIX i can use below command to print ,but what set-up i need to do . lpr -P<printer name> <report Name> Pls suggest me. Thanks Arpit (2 Replies)
Discussion started by: Arpitmitm
2 Replies

4. Programming

popen catching output and errors

I have code which at the moment only catches the command/program output if the program runs correctly, which is a small problem as I would like to capture everything from stdout inclusive of errors FILE *fp; fp = popen(command.c_str(), "r"); while(fgets(cbuf, 1024, fp) != NULL){ .....do stuff... (1 Reply)
Discussion started by: mshindo
1 Replies

5. UNIX for Advanced & Expert Users

Printing to Windows and maintaining control

I'm new at the entire spectrum of printing in Unix, and especially when--as I understand it--the printers are on a Windows server. At work we have a variety of printers and printing from Windows, or from Unix via lp or lpr works fine. The initial problem: Our users will be printing up to 20... (1 Reply)
Discussion started by: effigy
1 Replies

6. HP-UX

Printing from unix to windows.

Hi, This issue is killing me. I'm looking to get advise on setting up a remote printer in unix "HP-UX" which will print to a printer which sits remotely connected to a windows 2000 server. I guess I'm looking for an idiots guide - any assistance you may offer will be gratefully received. ... (2 Replies)
Discussion started by: pmaths
2 Replies

7. Shell Programming and Scripting

printing output more than 13

i want to print the idle time of the users more than 10 days. for eg: my "w" command output is like below. -sh-3.00$ w 03:47:41 up 13 days, 16:59, 3 users, load average: 10.00, 10.00, 10.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - ... (2 Replies)
Discussion started by: Krrishv
2 Replies

8. Solaris

Error message printing to Windows on port 515

Hello, We have an application which runs on Windows 2000 that responds to prrint requests by anyone using RFC1179 protocol on port 515. We are getting an error message when submitting print requests from Sun Solaris 9. "Windows 2000 LPD Server Error: Specified printer does not exist"... (0 Replies)
Discussion started by: pauls
0 Replies

9. UNIX for Advanced & Expert Users

Unix to Windows 2000 printing over the internet

I need help printing to the Windows 2000 Pro environement from a Unix box, that the Windows 2000 system dials into via a ISP. We are still waiting for our T1 line to be installed but will need to know if that process will change when that is installed. I know that you can print from Windows 2000... (1 Reply)
Discussion started by: supportit
1 Replies
Login or Register to Ask a Question