큰 sh 파일을 작은 sh 파일로 나누는 python 스크립트를 만든 다음 모든 sh 파일을 새 화면으로 보냅니다. 이 코드TypeError : 유니 코드로 강제 변환 : 쉘 스크립트를 만들 때 찾은 문자열 또는 버퍼 파일.
import os
splitLen = 2 # 2 lines per file
outputBase = 'US11_'
# This is shorthand and not friendly with memory
# on very large files (Sean Cavanagh), but it works.
input = open('US11.sh', 'r').read().split('\n')
at = 1
for lines in range(0, len(input), splitLen):
# First, get the list slice
outputData = input[lines:lines+splitLen]
# Now open the output file, join the new slice with newlines
# and write it out. Then close the file.
output = open(outputBase + str(at) + '.sh', 'w')
output.write('#!/bin/sh\n')
output.write('\n'.join(outputData))
output.write('\n')
output.close()
os.chmod('{}'.format(output), 0o777)
os.system("screen -m -d bash -c ./" + output)
# Increment the counter
at += 1
을 시도했지만 파이썬 파일을 실행하는 경우,이 오류는 다음 SH 파일에게 권한을 부여하고 보내기 이제 프로세스가 SH 파일에 분할 선을 작성해야
TypeError: coercing to Unicode: need string or buffer, file found
을 보여 주었다 sh 파일을 실행할 화면에 저장합니다. 그 후에 모든 파일에 대해 동일한 단계에서 프로세스를 완료하십시오.
내 코드의 오류는 무엇입니까? 어떤 생각?
오류의 ** 전체 추적 **을 포함 시키십시오. 그래서 어떤 행이 그 원인 일지 추측 할 필요가 없습니다. –
@MartijnPieters 죄송합니다. 나는 Enter를 누르고 코멘트가 불완전하게 게시되었다. 그것은 당신의 대답과 같은 코드였습니다! 형식 – power