我有以下脚本:
param([Parameter(Mandatory=$true)][string]$dest)
New-Item -force -path "$dest\1\" -itemtype directory
New-Item -force -path "$dest\2\" -itemtype directory
New-Item -force -path "$dest\3\" -itemtype directory
Copy-Item -path "C:\Development\1\bin\Debug\*" -destination "$dest\1\" -container -recurse -force
Copy-Item -path "C:\Development\2\bin\Debug\*" -destination "$dest\2\" -container -recurse -force
Copy-Item -path "C:\Development\3\bin\Debug\*" -destination "$dest\3\" -container -recurse -force
Run Code Online (Sandbox Code Playgroud)
该脚本采用一个字符串并将所有文件和文件夹从静态原始路径复制到给定的根字符串,为了结构清晰而修改一些文件夹。
它工作正常,但打印出“New-Item”命令的结果,我想隐藏它。我查看了有关 SE 的网络和其他问题,但没有找到我的问题的明确答案。
如果有人想知道 - 我在开头使用“New-item”是为了规避 PS' -recurse 参数中的缺陷,如果目标文件夹不存在,则不会正确复制所有子文件夹。(即它们是强制性的)
Powershell 可以监听并捕获按键吗?
是否可以编写一个 PowerShell 脚本,就像AutoHotkey一样,位于托盘中并等待您按下预定义的键盘键才开始执行?并且每次按下所述键时可能不会返回而是触发?
我想要实现的是 - 仅在启动脚本后按下按钮才执行预定义的脚本操作,因此将其放在桌面上并定义快捷键是行不通的。
例如:
我希望每次按“x”键时输入 3 次文本“TEST”,但我希望仅当执行此操作的脚本正在运行时才会发生这种情况。因此,当脚本未运行时 - 按“x”不会执行任何操作。
基本上,AutoHotkey 可以完全做到这一点,但如果可能的话,我想在 PowerShell 中执行此操作,而无需编写大量 C# 代码,因为那样我只需为此编写一个小型 C# 托盘应用程序。
据我所知,在PowerShell中使用$pwd和使用都可以./得到相同的结果。
他们是一样的还是有区别的?
我有以下代码,取自本MSDN:
public class First { }
public class Second : First { }
public delegate First SampleDelegate(Second a);
// Matching signature.
public static First ASecondRFirst(Second first)
{ return new First(); }
// The return type is more derived.
public static Second ASecondRSecond(Second second)
{ return new Second(); }
// The argument type is less derived.
public static First AFirstRFirst(First first)
{ return new First(); }
// The return type is more derived
// and the argument type is …Run Code Online (Sandbox Code Playgroud) 我见过一些C#方法,比如ThreadPool.QueueUserWorkItem(WaitCallback,Object),它采用一种方法(在本例中为"WaitCallback"),而不是提供一个直接将参数传递给方法的选项,而是单独Object使用供应他们.
所以你不能做像这里被问到的事情.
我的问题是:为什么?
必须有技术上的理由使用这种方法,不允许这样的东西
ThreadPool.QueueUserWorkItem(new WaitCallback(Multiply(2, 3)));
private int Multiply(int x,int y)
{
int z=(x*y);
return z;
}
Run Code Online (Sandbox Code Playgroud) powershell ×3
c# ×2
covariance ×1
hotkeys ×1
join ×1
keylogger ×1
keystroke ×1
lambda ×1
methods ×1
object ×1
pwd ×1
sql-server ×1
t-sql ×1