Advertisement
Guest User

ddsd

a guest
Jan 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. from __future__ import print_function
  2. import socket
  3. import sys
  4. import os
  5. import stat
  6.  
  7.  
  8. class Printer:
  9. def __init__(self, path="sys", name="stdout", permission=0o666, createnew=True):
  10. print("hallo")
  11. self.path = path
  12. self.name = name
  13. self.permission = permission
  14. self.sys = False
  15. self.full_path = "sys.stdout"
  16. self.fifo = self.full_path
  17. if(self.path == "sys" and self.name == "stdout"):
  18. self.fifo = sys.stdout
  19. self.fd = sys.stdout.fileno()
  20. self.out = os.fdopen(self.fd,'w',0)
  21. self.sys = True
  22. elif(self.path == "sys" and self.name == "stdin"):
  23. self.fifo = sys.stdin
  24. self.fd = sys.stdin.fileno()
  25. self.out = os.fdopen(self.fd,'w',0)
  26. self.sys = True
  27. elif(self.path == "sys" and self.name == "stderr"):
  28. self.fifo = sys.stderr
  29. self.fd = sys.stderr.fileno()
  30. self.out = os.fdopen(self.fd,'w',0)
  31. self.sys = True
  32. else:
  33. self.full_path = os.path.join(path,name)
  34. print(self.fifo)
  35. print(self.full_path)
  36. print(self.permission)
  37. if(os.path.exists(self.full_path)):
  38. if(createnew):
  39. os.remove(self.full_path)
  40. self.fifo = os.mkfifo(self.full_path, permission)
  41. self.fd = os.open(self.full_path, os.O_RDWR) #non-blocking
  42. self.out = os.fdopen(self.fd, 'w', 0) #also non-blocking
  43. else:
  44. self.fifo = os.mkfifo(self.full_path, permission)
  45. self.fd = os.open(self.full_path, os.O_RDWR) #non-blocking
  46. self.out = os.fdopen(self.fd, 'w', 0) #also non-blocking
  47.  
  48. def printex(self, *args):
  49. #os.remove(self.full_path)
  50. self.fifo = os.mkfifo("cool43333444.fifo", 0o777)
  51. self.out = open("cool43333444.fifo", "w") #non-blocking
  52. self.fd = self.out.fileno()
  53. #self.out = os.fdopen(self.fd, 'w', 0) #also non-blocking
  54. os.write(self.fd,"hallo\n")
  55. os.close(self.fd)
  56.  
  57. def close(self):
  58. if(self.sys==False):
  59. os.close(self.fd)
  60.  
  61.  
  62. def main():
  63. test = Printer(path="",name="test.fifo")
  64. test.printex("hallo eee")
  65. main()
  66. import socket
  67. import sys
  68. import os
  69.  
  70. myFile= open( "a.log", "w", 0 )
  71. sys.stdout=myFile
  72. print("fd\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement