【问题标题】:Execute command in terminal on startup on Pi在 Pi 上启动时在终端中执行命令
【发布时间】:2018-07-25 06:14:12
【问题描述】:

我在 Pi 上有一个简单的读卡器程序,它从 USB 读卡器(就像键盘一样)读取输入并将其写入文本文件。因此,要使该程序正常工作,该程序需要在终端上运行,以便检测来自读卡器的原始输入。我希望这个程序在每次我的 pi 打开时运行,所以我需要一种方法来打开终端并在启动时执行终端内的代码。谁能帮帮我?

import datetime
import time

card = raw_input()
t = datetime.datetime.now()

while True:
    f = open("Laptop Sign Out" + '.txt', 'a')
    f.write("Card Number: " + card[1:10] + " Time: " + t.strftime("%m-%d-%Y %H:%M:%S"))
    f.write('\n')
    f.write(';')
    f.write('\n')
    f.close()
    time.sleep(5)

gpio.cleanup()

【问题讨论】:

  • 不能把程序的命令加到~/.bashrc吗?

标签: python terminal raspberry-pi


【解决方案1】:

您首先需要制作一个 sh/bash 脚本:

#!/usr/bin/bash
(sudo) python <file_address>

从那里,这应该会有所帮助: https://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up

【讨论】:

  • 我需要在启动时打开终端窗口并在其中执行程序,以便读取读卡器输入。我的方法有问题还是你知道另一种方法?
猜你喜欢
  • 1970-01-01
  • 2019-10-21
  • 1970-01-01
  • 2016-04-05
  • 2021-03-04
  • 2010-11-19
  • 2016-10-06
  • 2018-11-14
  • 1970-01-01
相关资源
最近更新 更多