0

I'm writing an auto-testing script right now. My build environment is Linux with Python 3.

My program stuck when it runs to the command:

os.system('cp '+ file_name + '  '+ usb_port)

where it reports:

cp: cannot create regular file `/dev/usb/lp0': No such file or directory

I have manually checked that two file exist. (well i should say that the usb port is indeed connected and working properly by using path.exist command) I've separated this troubling command to another file,and it works fine without any error report.

my program involves following library:

import serial

import time

import os

import threading

import queue

import multiprocessing as mp

from datetime import datetime

from configparser import SafeConfigParser
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Jacky Zhang
  • 47
  • 1
  • 1
  • 5
  • Are you trying to write a file to your printer? What you are doing is to replace the dev filesystem entry of your printer. Read the file and write to the device entry, no external call needed. – Klaus D. Jun 06 '16 at 03:43
  • Thanks for the reply. I did a little search on Google but I'm not sure how to write files into device entry(most of results that popped up are about writing stuff into files.). I'm new to python, and I'm not very confident with it. Could you be more specific on how to replace the entry? – Jacky Zhang Jun 06 '16 at 04:57
  • You do not replace the entry, whatever this means. You *open* the file and *write* to it, then *close* it. – n. m. could be an AI Jun 06 '16 at 05:39
  • Thanks, I thought lp0 is a directory not a file. I get it. – Jacky Zhang Jun 06 '16 at 05:47
  • Or simply `os.system('cat '+ file_name + ' > '+ usb_port)` – Martin Beckett Jun 08 '16 at 04:43
  • I tried with 'cat' before though,and it generated the same error report as 'cp' did. – Jacky Zhang Jun 12 '16 at 01:20
  • @KlausD. It's such a strange case where I tried to open and read it where it reports that, again, file does not exit. – Jacky Zhang Jun 13 '16 at 01:35
  • Okay I finally know where it goes wrong. The error is due to the fact that the printer is trying to make a new file at /dev/usb/lp0 when I'm trying to overwrite it. Adding time.sleep(1) solves it perfectly. – Jacky Zhang Jun 13 '16 at 08:21

0 Answers0