我想在不使用root的情况下在mac os x上启动.sh类型或.py文件,我在google搜索并发现launchctl可以帮助我,
所以我读教程并在教程中做同样但它不适合我,[我使用mac os x 10.9 x64]
我的.plist文件[每隔60秒运行1.sh文件]:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.alvin.crontabtest</string>
<key>ProgramArguments</key>
<array>
<string>/Users/paul/Desktop/1.sh</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>60</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/AlTest1.err</string>
<key>StandardOutPath</key>
<string>/tmp/AlTest1.out</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
1.sh的来源:
echo '+' >> /Users/paul/Desktop/worked.txt
Run Code Online (Sandbox Code Playgroud)
我将Run.plist放在/Users/paul/Run.plist中
并从终端运行命令:
launchctl load /Users/paul/Run.plist
Launchctl start com.alvin.crontabtest
Run Code Online (Sandbox Code Playgroud)
命令执行没有任何错误,但我没有看到working.txt中的任何内容
有人可以帮我吗?
显然,在PowerShell(第3版)中并非所有$null都是相同的:
>function emptyArray() { @() }
>$l_t = @() ; $l_t.Count
0
>$l_t1 = @(); $l_t1 -eq $null; $l_t1.count; $l_t1.gettype()
0
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
>$l_t += $l_t1; $l_t.Count
0
>$l_t += emptyArray; $l_t.Count
0
>$l_t2 = emptyArray; $l_t2 -eq $null; $l_t2.Count; $l_t2.gettype()
True
0
You cannot call a method on a null-valued expression.
At line:1 char:38
+ $l_t2 = emptyArray; $l_t2 -eq $null; $l_t2.Count; $l_t2.gettype()
+ ~~~~~~~~~~~~~~~
+ CategoryInfo …Run Code Online (Sandbox Code Playgroud) 如果它结束,我需要修剪路径\.
C:\Ravi\
Run Code Online (Sandbox Code Playgroud)
我需要换到
C:\Ravi
Run Code Online (Sandbox Code Playgroud)
我有一个路径不会结束的情况\(然后它必须跳过).
我尝试过.EndsWith("\"),但是当我有\\而不是时,它失败了\.
这可以在PowerShell中完成,而无需诉诸条件吗?
我正在做一些测试,偶然发现了以下情况:
您可以根据需要重载PoShv5中的方法.如果调用不带参数的方法,它可以在内部使用参数调用方法,以保持代码不冗余.我预计这对于构造函数也是如此.
在此示例中,最后一个构造函数按预期工作.其他构造函数仅返回没有设置值的对象.
Class car {
[string]$make
[string]$model
[int]$Speed
[int]$Year
speedUp (){
$this.speedUp(5)
}
speedUp ([int]$velocity){
$this.speed += $velocity
}
# Constructor
car () {
[car]::new('mall', $Null, $null)
}
car ([string]$make, [string]$model) {
[car]::new($make, $model, 2017)
}
car ([string]$make, [string]$model, [int]$Year) {
$this.make = $make
$this.model = $model
$this.Year = $year
}
}
[car]::new() # returns "empty" car
[car]::new('Make', 'Nice model') # returns also an "empty" one
[car]::new( 'make', 'nice model', 2017) # returns a "filled" instance
Run Code Online (Sandbox Code Playgroud)
有没有办法来解决这个问题?我错过了什么?
powershell constructor overloading class constructor-chaining
Coroutine async返回Deferred<T>,有懒惰执行和等待用法的例子.
但是,我们如何等待任何一个Deffered实例完成?
简而言之
// whats the equivalent of CompletableFuture.anyOf(...)?
// is this how we do it? if so how costly is this?
select<Unit> {
deffered1.onAwait {}
deffered2.onAwait {}
}
Run Code Online (Sandbox Code Playgroud) 有没有办法告诉cat命令在没有收到任何数据时停止阅读?可能有一些"超时",指定没有数据传入多长时间.
有任何想法吗?
在ms上,从node.js代码开始,如何c:\documents在Windows文件浏览器中打开特定目录(例如:)?
我想在c#中,它会是:
process.Start(@"c:\test")
Run Code Online (Sandbox Code Playgroud) 所以我有这个代码:
$userprofile=Get-ChildItem Env:USERPROFILE
$localpath="$userprofile\some\path"
Run Code Online (Sandbox Code Playgroud)
我希望下面的输出来自$localpath:
c:\users\username\some\path
Run Code Online (Sandbox Code Playgroud)
但是我得到的是:
System.Collections.DictionaryEntry\some\path
Run Code Online (Sandbox Code Playgroud)
所以,当然,像cd $localpath失败的东西.我如何实现我的需求?
我正在努力为PowerShell划清界限.我的理解非常有限:
谁能更好地解释这些概念?是否有某种维恩图或其他能够充实这些信息的东西?在线文档并没有太大帮助.
使用此代码,我打开 excel(使用visible = false,以便用户看不到它),写入工作簿,然后在脚本结束后打开 excel(使其可见)或完全关闭它而不保存。当我保存 Excel、使其保持打开状态、结束脚本,然后稍后手动关闭 Excel 时,任务管理器中没有后台进程。但是,当我使用脚本关闭 Excel 时,它仍保留在任务管理器中。
以下是我开始使用 Excel 的方法:
$script:excel = new-object -ComObject excel.application # create excel object
$excel.visible = $false # hide excel window
$script:workbook = $excel.Workbooks.Add() # add excel file
$script:ws1 = $workbook.Worksheets.Item(1) # create new sheet
Run Code Online (Sandbox Code Playgroud)
这是我关闭它的方法:
[gc]::Collect()
[gc]::WaitForPendingFinalizers()
if ($script:closeOnX) {
#only do this if not keeping excel open
Write-Host "Closing Excel"
$excel.Quit()
}
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel)
Run Code Online (Sandbox Code Playgroud)
closeOnX 只是一个标志,因此它仅在某些情况下实际关闭 Excel 应用程序。其余部分在每次脚本结束时执行。
当我结束脚本并同时关闭 Excel 时,我只想关闭当前的 Excel 进程(这就是我不想停止进程的原因),而不关闭用户可能正在处理的其他工作簿。
当我结束脚本、保存并打开 Excel 时,我希望当用户手动关闭 Excel 时所有进程都消失。(这是工作)
powershell ×5
filepath ×2
appdomain ×1
bash ×1
cat ×1
class ×1
com ×1
constructor ×1
coroutine ×1
cron ×1
ends-with ×1
excel ×1
kotlin ×1
launchd ×1
linux ×1
macos ×1
node.js ×1
null ×1
overloading ×1
rcw ×1
runspace ×1
session ×1
sh ×1
shell ×1
startup ×1
string ×1
text-parsing ×1
unix ×1
windows ×1