Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#web表单应用程序启动NodeJS应用程序_C#_Node.js_Winforms_Meteor_Command Line - Fatal编程技术网

从C#web表单应用程序启动NodeJS应用程序

从C#web表单应用程序启动NodeJS应用程序,c#,node.js,winforms,meteor,command-line,C#,Node.js,Winforms,Meteor,Command Line,我已经构建了MeteroJS应用程序,我想从C#代码开始作为NodeJS应用程序 下面是Windows窗体应用程序,它用作启动和停止NodeJS应用程序的控制面板 我可以使用命令行手动启动NodeJS应用程序:(这很有效!) 我想从命令行重复上面的所有操作,这次是在C#应用程序中 这是单击“开始”按钮时执行的代码: Environment.SetEnvironmentVariable("MONGO_URL", String.Format("mongodb://{0}:{1}@localhost

我已经构建了MeteroJS应用程序,我想从C#代码开始作为NodeJS应用程序

下面是Windows窗体应用程序,它用作启动和停止NodeJS应用程序的控制面板

我可以使用命令行手动启动NodeJS应用程序:(这很有效!)

我想从命令行重复上面的所有操作,这次是在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");
我甚至不确定这是否可能。这根本不起作用,没有留下任何日志。
请检查我做错了什么并提出建议。

使用以下代码执行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();

此代码可能会帮助您:

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();

它可以工作,所以问题是文件名没有设置为node.exe路径?是的,我们需要提到路径..@eomeroffFolder Debug\server包含app.js
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();