简体   繁体   English

env 命令替代 windows powershell/cmd

[英]env command alternative for windows powershell/cmd

I saw one cool thing in Linux and wondering if it is also available in Windows. In order to run another program in a custom environment without modifying the current one, in Linux we use env command, like this: env USERNAME="Test" PASSWORD="Test" npm run e2e:test .我在 Linux 中看到一件很酷的东西,想知道它是否也可以在 Windows 中使用。为了在自定义环境中运行另一个程序而不修改当前程序,在 Linux 中我们使用env命令,如下所示: env USERNAME="Test" PASSWORD="Test" npm run e2e:test Here basically what it does is that e2e tests start running (it can be any type of process in any technology, not just e2e tests in nodejs) but with test user credentials and not with predefined actual user credentials.这里基本上它所做的是 e2e 测试开始运行(它可以是任何技术中的任何类型的进程,而不仅仅是 nodejs 中的 e2e 测试)但是使用测试用户凭证而不是使用预定义的实际用户凭证。

How can I achieve this in Windows?我怎样才能在 Windows 中实现这一点?

Call cmd.exe with a command-line script it will execute in its context.使用将在其上下文中执行的命令行脚本调用cmd.exe Effectively this:实际上是这样的:

cmd.exe /c "set USERNAME=Test && set PASSWORD=Test && npm run mytest"

I solved this and many other OS related issues by installing WSL and using it via powershell.我通过安装 WSL并通过 powershell 使用它解决了这个问题和许多其他与操作系统相关的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM