python - 如何从 Python 在终端上执行多个命令
问题描述
目前正在尝试在 Ubuntu 上通过加密压缩几个文件。
我需要它们是.zip。
我通常会做的是在终端中写:
zip -e secretDir.zip secretFile.txt
这通常会要求输入密码,例如:
Enter password: secret
Verify password: secret
除了实际上没有显示密码之外。这工作得很好。
但是我试图从我的 Python 脚本(3.7)中做到这一点。
我有subprocess.call(['zip', '-e', fileName + '.zip', fileName + '.txt'])
这很好用,但是我现在应该如何告诉 zip 密码是什么?
欢迎在压缩文件时可能进行加密的开源库。我已经听说过 chilkat 和 CkPython。
解决方案
您可以使用参数将密码直接传递给zip
命令-p
。
subprocess.call(['zip', '-P', 'MyPassW0rd123', fileName + '.zip', fileName + '.txt'])
推荐阅读
- java - Unable to fork in spring-boot-maven-plugin
- php - 检查字符串是否有除连字符以外的特殊字符?
- yarnpkg - error while publishing package - "name" is invalid for new packages
- java - 如何在spring boot rest api中获取服务器路径
- javascript - Jscript element.style 在 script.js 中不起作用(Visual Studio 代码)
- python - Python Pandas Dataframes:使用行值创建列
- android - Remove CALL_LOG and SMS permission in ejected React Native app
- javascript - Materialize:如何以编程方式打开和关闭可折叠项
- php - 如何在 Laravel 中使用 Eloquent 创建动态模型?
- react-native - I can't install expo-cli