Skip to content

Instantly share code, notes, and snippets.

@wojkos
Created January 30, 2019 20:49
Show Gist options
  • Save wojkos/0f422e8d1582dc37d7c921503c036492 to your computer and use it in GitHub Desktop.
Save wojkos/0f422e8d1582dc37d7c921503c036492 to your computer and use it in GitHub Desktop.
import subprocess
# var = subprocess.call("date")
# subprocess.call(["ls", "-l", "/etc/hosts"])
# p = subprocess.Popen("date", stdout=subprocess.PIPE, shell=True)
# (output, err) = p.communicate()
# print("Today is", output)
# p = subprocess.Popen(["ls", "-l", "/etc/hosts"], stdout=subprocess.PIPE)
# output, err = p.communicate()
# print("*** Running ls -l command ***\n", output)
# p = subprocess.Popen(["cat", "/etc/hosts", "|", "wc", "-l"], stdout=subprocess.PIPE)
# output, err = p.communicate()
# print(output)
# p = subprocess.Popen("date", stdout=subprocess.PIPE, shell=True)
# p1 = subprocess.Popen(["cat", "/etc/hosts"], stdout=subprocess.PIPE)
# p2 = subprocess.Popen(["wc", "-l"], stdin=p1.stdout, stdout=subprocess.PIPE)
# output = p2.communicate()[0]
# print(output)
def create_file(file_name, dir):
cmd ="touch {}/{}".format(dir, file_name)
# print(cmd.split())
subprocess.call(['touch', "{}".format(file_name)], cwd = "{}".format(dir))
# # def create_file(file_name):
# # cmd ="touch {}".format(file_name)
# # print(cmd.split())
# # subprocess.call('cmd.split('))
create_file('create_by_code.txt', '/')
# subprocess.call(['ls', '-l'], cwd= '/home/wojtek/Desktop/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment