有没有办法在没有执行bat文件的情况下使用npm start而不使用命令提示符? [英] Is there any way to use npm start without execute bat file and not using command prompt?
本文介绍了有没有办法在没有执行bat文件的情况下使用npm start而不使用命令提示符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在项目中安装了node.js和npm。
要启动npm,我需要手动运行bat文件。由于服务器的安全性,我也不想在c#代码中运行bat文件。
我尝试了什么:
这是我的蝙蝠档案。
I installed node.js and npm in my project.
To start npm, I need to run bat file manually. I don't want to run bat file in c# code too because of server security.
What I have tried:
This is my bat file.
@ECHO off
set MYINFO_APP_CLIENT_ID=MyInfo_SelfTest
set MYINFO_APP_CLIENT_SECRET=password
set MYINFO_APP_REDIRECT_URL=http://localhost:3001/callback
set MYINFO_APP_REALM=http://localhost:3001
npm start
推荐答案
您可以在C#中获得相同的结果。为此,您需要设置四个环境变量,然后启动该过程。
Environment.SetEnvironmentVariable方法(字符串,字符串) [ ^ ]
Process.Start方法(字符串,字符串) [ ^ ]
类似于:
You can achieve the same result in C#. For that, you need to set the four environment variables and then launch the process.
Environment.SetEnvironmentVariable Method (String, String)[^]
Process.Start Method (String, String)[^]
Something like:
Environment.SetEnvironmentVariable("MYINFO_APP_CLIENT_ID", "MyInfo_SelfTest");
Environment.SetEnvironmentVariable("MYINFO_APP_CLIENT_SECRET", "password");
Environment.SetEnvironmentVariable("MYINFO_APP_REDIRECT_URL", "http://localhost:3001/callback");
Environment.SetEnvironmentVariable("MYINFO_APP_REALM", "http://localhost:3001");
Process.Start("npm", "start");
您可能必须指定npm可执行文件的完整路径。
亲切。
You may have to specify the full path to the npm executable.
Kindly.
这篇关于有没有办法在没有执行bat文件的情况下使用npm start而不使用命令提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文