我有这个shell脚本Test.sh:
#! /bin/bash
FILE_TO_CHECK="/Users/test/start.txt"
EXIT=0
while [ $EXIT -eq 0 ]; do
if [ -f "$FILE_TO_CHECK" ]
then
/usr/bin/java -jar myapp.jar
EXIT=1
else
sleep 30
fi
done
Run Code Online (Sandbox Code Playgroud)
我需要在登录后自动启动此脚本.
所以我把它放在一个文件夹Test中/System/Library/StartupItems/
当我重新启动Mac时,登录后没有任何反应.有任何线索吗?
我也尝试过Automator,但结果相同:java程序没有运行.
我需要检查文件是否包含特定行.这个文件是由某人连续写的,所以我把检查放在while循环中.
FILE="/Users/test/my.out"
STRING="MYNAME"
EXIT=1
while [ $EXIT -ne 0 ]; do
if [ -f $FILE ] ; then CHECK IF THE "STRING" IS IN THE FILE - IF YES echo "FOUND"; EXIT=0; fi
done
Run Code Online (Sandbox Code Playgroud)
该文件包含文本和多行.
我开始在python中使用TK为我的程序构建一个图形界面.我无法修复2个问题:(1)窗口中按钮的位置和(2)在一个功能内使用一个无线电按钮的值.
这是我目前的代码:
root = tk.Tk()
root.title("START")
root.geometry("500x200+500+200")
v = tk.IntVar()
v.set(0) # initializing the choice
my_choise = [
("Basic",1),
("Advanced",2),
('Extreme',3)
]
def ShowChoice():
print(v.get())
tk.Label(root,
text="""Choose your configuration:""",
justify = tk.LEFT,
padx = 20).pack()
val = 0
for val, choise in enumerate(my_choise):
tk.Radiobutton(root,text=choise,padx = 20,variable=v,command=ShowChoice,value=val).pack(anchor=tk.W)
def star_program(value):
os.system("ifconfig")
def open_comments_file():
os.system("gedit /home/user/Desktop/comments.txt")
def open_links_file():
os.system("gedit /home/user/Desktop/links.txt")
frame = tk.Frame(root)
frame.pack()
open_file_c = tk.Button(frame,
text="Comments",
command=open_comments_file)
open_file_f = tk.Button(frame,
text="Links",
command=open_links_file)
button = tk.Button(frame,
text="Start",
command=star_program(v.get()))
button.pack(side=tk.LEFT)
open_file_f.pack(side=tk.LEFT)
open_file_c.pack(side=tk.LEFT)
slogan …Run Code Online (Sandbox Code Playgroud) 我在Windows上开发了一个使用此代码的sikuli python脚本:
from socket import AF_INET, SOCK_DGRAM
import sys
import socket
import struct, time
host = "pool.ntp.org"
port = 123
buf = 1024
address = (host,port)
msg = '\x1b' + 47 * '\0'
# reference time (in seconds since 1900-01-01 00:00:00)
TIME1970 = 2208988800L # 1970-01-01 00:00:00
# connect to server
client = socket.socket( AF_INET, SOCK_DGRAM)
client.sendto(msg, address)
msg, address = client.recvfrom( buf )
t = struct.unpack( "!12I", msg )[10]
t -= TIME1970
current_time = time.ctime(t).replace(" "," ")
Run Code Online (Sandbox Code Playgroud)
代码在linux下或在Windows上的python脚本中正常工作,但是如果我在Windows上的sikulix上使用此代码它会崩溃(在line => …
我想通过终端在我的MAC OS中安装dmg java包
我尝试使用这个命令:
sudo installer -package jdk-7u51-macos-x64.dmg -target /
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
installer: Error the package path specified was invalid: 'jdk-7u51-macos-x64.dmg'
Run Code Online (Sandbox Code Playgroud) 我有一个表示浮点数的字符串:
echo $NUM
5.03
Run Code Online (Sandbox Code Playgroud)
我需要将此数字乘以MEGA。如果我直接这样做:
MEGA="1000"
result=$(($NUM*$MEGA))
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
syntax error: invalid arithmetic operator (error token is ".03 * 1000")
Run Code Online (Sandbox Code Playgroud) 我想使用git log指定我的存储库的路径来获取最后10次提交.我使用了选项-path,但我有"存储库外"错误
git log --no-merges -10 -p /home/my_folder/git/repo
fatal: /home/my_folder/git/repo: '/home/my_folder/git/repo' is outside repository
Run Code Online (Sandbox Code Playgroud)
该命令正在例如文件夹/ home中运行
我正在逐行读取文件。当我找到特定字符串时,我想分析以下几行,直到出现特定字符。具体来说。这是我的输入文件:
blabbal
blabbalb
blablab
info {
(bbbbb,
ccccc,
dddddddddd,
eeeeeeeeeeeeeee
fffffffffffffff);
xxxxxxxxxxxxxxx,
rrrrrrrrrrrrrrr,
};
blabbal
Run Code Online (Sandbox Code Playgroud)
我正在使用读取文件
File.open("example.txt", "r").each_line do |line|
Run Code Online (Sandbox Code Playgroud)
然后我想:1)当我找到字符串“info”时,在 while 循环内迭代下一行,直到找到字符“);”
这是我当前代码的示例:
File.open("example.txt", "r").each_line do |line|
if (line.include?("info") == true)
while(1) do
puts line
next if line.include?(")") == false
end
end
end
Run Code Online (Sandbox Code Playgroud)
似乎它不会转到下一行(“puts”始终打印同一行 - >“info {”)