나는 apt-get
go 프로그램에서 via exec를 사용하고 있습니다. 이와 같이:
func aptInstall(pkg, ver string) {
args := []string{"install", "-y", fmt.Sprintf("%s=%s", pkg, ver)}
cmd := exec.Command("apt-get", args...)
cmd.Env = append(os.Environ(), "LANG=en")
out, err := cmd.CombinedOutput()
log("apt install", "cmd", fmt.Sprintf("apt-get %s",
strings.Join(args, " ")), "out", string(out), "err", err)
}
기록된 메시지에는 다음이 포함됩니다.
Selecting previously unselected package nnrforms.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 219690 files and directories currently installed.)
Preparing to unpack .../nnrforms_531-82a94c0_amd64.deb ...
Unpacking nnrforms (531-82a94c0) ...
Setting up nnrforms (531-82a94c0) ...
[0;1;31mFailed to reload nginx.service: Unit nginx.service not found.[0m
대화형 모드에서 실행되지 않고 있음을 어떻게 알 수 apt-get
있고 진행 메시지를 표시하지 않을 수 있습니까(예: Reading database ...
ANSI-ESC 색상 추가 안 함)?
고쳐 쓰다
두 가지 답변을 모두 시도했지만 색상은 세트별로 제거되었지만 TERM=dumb
진행 정보는 여전히 남아 있습니다.
- 20230518_144401.646+0800: apt install
cmd: apt-get install -qqqy -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" a2up=72-5683a16
err: <nil>
out:
- 20230518_144414.275+0800: apt remove
cmd: apt-get remove -qqqy -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" a2s
err: exit status 100
out: |
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 219699 files and directories currently installed.)
Removing a2up (72-5683a16) ...
Failed to disable unit: Unit file a2up.service does not exist.
dpkg: error processing package a2up (--remove):
installed a2up package post-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
a2up
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
-qqqy
대부분의 출력 메시지는 표시 되지 않지만 apt-get install
작동하지 않는 것 같습니다 apt-get remove
.
답변1
-q
-qq
, 를 사용하여 출력의 자세한 정도를 제어하고 -qqq
경고를 억제 할 수 있습니다 .2>/dev/null
sudo apt install neofetch -yq -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" 2> /dev/null
-o Dpkg::Progress-Fancy="0"
진행률 표시줄 취소
-o APT::Color="0"
색상 사용 비활성화
-o Dpkg::Use-Pty="0"
Reading database
메시지 숨기기
난 달린다
sudo apt install neofetch -yq -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" 2> /dev/null > out
도움이 되었기를 바랍니다