eom*_*off 2 c# command-line winforms node.js meteor
我已经构建了 MeteroJS 应用程序,我想从 C# 代码作为 NodeJS 应用程序启动它。
这是 Windows 窗体应用程序,用作启动和停止 NodeJS 应用程序的控制面板
我可以使用命令行手动启动 NodeJS 应用程序:(这有效!)
set MONGO_URL=mongodb://someAdmin:password@localhost:27017/some_db
set ROOT_URL=http://someservice:8080
set PORT=8080
node bundle\main.js
Run Code Online (Sandbox Code Playgroud)
我想从命令行重复上面的所有操作,这次是在 C# 应用程序中。
这是在单击开始按钮时执行的代码:
Environment.SetEnvironmentVariable("MONGO_URL", String.Format("mongodb://{0}:{1}@localhost:27017/{2}", usernameTxt.Text, passwordTxt.Text, databaseTxt.Text), EnvironmentVariableTarget.Machine);
Environment.SetEnvironmentVariable("ROOT_URL", String.Format("http://someservice:{0}", portTxt.Text), EnvironmentVariableTarget.Machine);
Environment.SetEnvironmentVariable("PORT", portTxt.Text, EnvironmentVariableTarget.Machine);
Process.Start("CMD.exe", @"/C node bundle\main.js");
Run Code Online (Sandbox Code Playgroud)
我不确定这是否可能。这根本不起作用并且没有留下任何日志。你能不能检查一下我做错了什么并提出建议。
小智 5
使用以下代码执行node.js cmd
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"c:\node\node.exe";**//Path to node installed folder****
string argument = "\\ bundle\main.js";
p.StartInfo.Arguments = @argument;
p.Start();
Run Code Online (Sandbox Code Playgroud)
小智 5
此代码可以帮助您:
Process p = new Process();
p.StartInfo.WorkingDirectory= @"C:\Users\USERNAME\Documents\Visual Studio 2015\Projects\Proyecto 1.3\Proyecto 1.3\bin\Debug\server";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c node app.js";
p.Start();
Run Code Online (Sandbox Code Playgroud)