110,566
社区成员
发帖
与我相关
我的任务
分享
private string CommandLine(string name, params string[] args)
{
return CommandLine(name, "", args);
}
/// <summary>
/// 调用命令行工具
/// </summary>
/// <param name="name">命令行工具名称</param>
/// <param name="workingDirectory">设置工作目录</param>
/// <param name="args">可选命令行参数</param>
/// <remarks>注意:所有命令行工具都必须保存于system32文件夹中</remarks>
/// <returns></returns>
private string CommandLine(string name, string workingDirectory, params string[] args)
{
string returnValue = "";
using (Process commandline = new Process())
{
try
{
commandline.StartInfo.UseShellExecute = false;
commandline.StartInfo.CreateNoWindow = true;
commandline.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
commandline.StartInfo.RedirectStandardOutput = true;
commandline.StartInfo.FileName = name;
commandline.StartInfo.WorkingDirectory = workingDirectory;
//添加命令行参数
if (args.Length > 0) commandline.StartInfo.Arguments = string.Join(" ", args);
commandline.Start();
commandline.WaitForExit();
returnValue = commandline.StandardOutput.ReadToEnd();
commandline.Close();
}
catch
{
commandline.Dispose();
throw;
}
}
return returnValue;
}
#endregion
/// <summary>
/// 调用osql.exe执行数据库脚本
/// </summary>
private void invoking(string strdatabase)
{
string str = "http://app.100to.com/Test/image/sqlscript.sql";
string[] args = new string[5];
args[0] = "-U " + "BQS"; //用户名
args[1] = "-P " + "bqs_2010@123"; //用户密码
args[2] = "-S " + "ec.100to.com,8899"; //服务器
args[3] = "-d " + "Wsb_" +strdatabase; //数据库
args[4] = "-i " + AppDomain.CurrentDomain.BaseDirectory + str; //sql脚本路径
//执行
HiddenField1.Value = CommandLine("osql.exe", args);
}