我的Powershell脚本,Foo.ps1:
Function Foo($directory)
{
echo $directory
}
if ($args.Length -eq 0)
{
echo "Usage: Foo <directory>"
}
else
{
Foo($args[0])
}
Run Code Online (Sandbox Code Playgroud)
从Windows控制台:
powershell -command .\Foo.ps1
Run Code Online (Sandbox Code Playgroud)
结果:"术语'.\ Foo.ps1'未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是正确的,然后再试一次."
尽管Foo.ps1位于我调用Powershell的当前目录中.然后我试着调用它来指定脚本文件的完整路径; 因为这条路径包含一个空间我相信我必须以某种方式引用它.此外,我需要将参数传递给脚本,该脚本也是包含一个或多个空格的文件名.无论我尝试什么,我都无法让它发挥作用.到目前为止,这是我最好的猜测:
powershell -command "'C:\Dummy Directory 1\Foo.ps1' 'C:\Dummy Directory 2\File.txt'"
Run Code Online (Sandbox Code Playgroud)
这在表达式或语句中给出了错误"Unexpected token'C:\ Dummy Directory 2\File.txt'.在行:1 char:136".
编辑:我找出了原因
powershell -command .\Foo.ps1
Run Code Online (Sandbox Code Playgroud)
不工作.这是因为我的Microsoft.PowerShell_profile.ps1文件有
cd C:\
所以,一旦powershell启动它就会改变目录.
我需要加载一些在顶部有这个的xhtml文件:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Run Code Online (Sandbox Code Playgroud)
每个文件都将加载到单独的System.Xml.XmlDocument中.由于DOCTYPE声明,它们需要很长时间才能加载.我尝试设置XmlResolver = null,但后来我抛出了XmlException,因为我有无效的实体(例如,").所以我认为我可以为第一个XmlDocument下载DTD,并以某种方式将其重用于后续的XmlDocuments(从而避免性能损失),但我不知道如何做到这一点.
我正在使用.Net 3.5.
谢谢.
我在C#,.NET framework 2.0中编写了一个Windows窗体应用程序,用于System.Data.OleDb
与SQL Server 2000数据库通信,该数据库工作正常.我现在需要增强应用程序以与AS/400上的DB2数据库通信.这只是配置连接字符串的问题,还是我需要其他驱动程序软件(来自哪里)和/或项目中的引用?
我想仍然使用OLEDB,但使用DB2.
编辑:我下载了Microsoft OLE DB提供程序但无法将其安装到我的桌面开发PC上,因为我没有安装SQL Server.此提供程序似乎仅用于将SQL Server与DB2集成,而我希望将Windows窗体应用程序与DB2集成.对于不需要SQL Server的OLE DB提供程序,是否有不同的下载位置,我可以从Windows桌面使用它?
我想通过反射调用一个显式实现的接口方法(BusinessObject2.InterfaceMethod),但是当我使用下面的代码尝试这个时,我得到一个Type.InvokeMember调用的System.MissingMethodException.非接口方法可以正常工作.有没有办法做到这一点?谢谢.
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace Example
{
public class BusinessObject1
{
public int ProcessInput(string input)
{
Type type = Assembly.GetExecutingAssembly().GetType("Example.BusinessObject2");
object instance = Activator.CreateInstance(type);
instance = (IMyInterface)(instance);
if (instance == null)
{
throw new InvalidOperationException("Activator.CreateInstance returned null. ");
}
object[] methodData = null;
if (!string.IsNullOrEmpty(input))
{
methodData = new object[1];
methodData[0] = input;
}
int response =
(int)(
type.InvokeMember(
"InterfaceMethod",
BindingFlags.InvokeMethod | BindingFlags.Instance,
null,
instance,
methodData));
return response;
}
}
public interface IMyInterface
{
int …
Run Code Online (Sandbox Code Playgroud) 我有这些功能:
function A1()
{
return B() && C();
}
function A2()
{
return
B() &&
C();
}
function B()
{
return true;
}
function C()
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
调用A1返回true,但A2返回undefined.A1和A2之间的唯一区别是空白区域.到底是怎么回事?在我的实际代码中,我不想将我的A1函数编写为单行,因为它会很长并且不易读.
我正在尝试在远程计算机上执行notepad.exe,但它现在不能正常工作.我错过了什么?
var ui = new ImpersonateUser();
//the process to restart
const string processName = "notepad.exe";
var serverName = "serverName";
try
{
//Use adbadmin for access
ui.Impersonate(_domain, _userName, _pass);
//Start the process
ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = @"C:\PsTools\psexec.exe";
info.Arguments = @"""\\" + serverName + @"C:\WINDOWS\notepad.exe""";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
lblStatusResponse.Text = "Service " + processName + " was restarted correctly.";
}
catch (Exception ex)
{
lblStatusResponse.Text = ex.ToString();
}
finally
{
ui.Undo();
} …
Run Code Online (Sandbox Code Playgroud)