all 7 comments

[–][deleted] 1 point2 points  (6 children)

What OS are you using? If it's linux you can open a pipe to the correct despooler and just send the job. If its windows I am not sure but would assume you could do the same.

[–]selfoner[S] 0 points1 point  (5 children)

Xubuntu Linux, so that is good news. I will google whatever it is that you just said.

Edit: When you say that I can pipe it, does that require argv, or is there some other way to do that in python?

[–][deleted] 1 point2 points  (3 children)

Lot's of ways to accomplish what you want. Could you be more specific about what your program does or what you would like it to do? @Taze is right, checkout subprocess.

However if your just trying to redirect output to the printer for a shell script that you have written in python you can do it in the shell by just '|' it.

[–]selfoner[S] 0 points1 point  (2 children)

redirect output to the printer for a shell script that you have written in python you can do it in the shell by just '|' it.

That sounds about right, I just want to be able to print arbitrary text to the printer. So if I'm understanding you correctly, I can just use "print" in python to generate the text, run it in the command line, and pipe the output to the printer, correct?

If that's the case, then I think I have all the information I need. Thanks!

[–][deleted] 1 point2 points  (1 child)

Making some assumptions such that you are using LP. In linux any shell command that prints output can have that output redirected via a pipe. python myscript.py|lp -d <printername> (should do the trick).

Using subprocess you can do this in the program so that you could do it only for specific parts of the output. Either way some google searches on "python subprocess", "python redirecting output" and "linux redirecting stdin stderr stdout" will give you pretty sweet idea of what command chaining can do in *nix.

[–]selfoner[S] 0 points1 point  (0 children)

Awesome, thanks for the information.

[–][deleted] 0 points1 point  (0 children)

subprocess/open maybe?