英文:
javac Foo.java && java Foo in windows vscode terminal not work
问题
I'd like to command javac & java
at the same time but it's not work and it return below exception :
在第1行第17个字符处:
+ javac Demo.java & java Demo
+ ~~
在此版本中,“&” 不是有效的语句分隔符号。
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
if i run separately it's work
PS D:\git\ITWeiHanDEV\Java> javac Demo.java
PS D:\git\ITWeiHanDEV\Java> java Demo
ps :
- my version is java8
- it's
windows 10 visual studio code terminal
英文:
I'd like to command javac & java
at the same time but it's not work and it return below exception :
At line:1 char:17
+ javac Demo.java && java Demo
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
if i run separately it's work
PS D:\git\ITWeiHanDEV\Java> javac Demo.java
PS D:\git\ITWeiHanDEV\Java> java Demo
ps :
- my version is java8
- it's
windows 10 visual studio code terminal
答案1
得分: 2
我尝试将 vscode 终端类型更改为 cmd
而不是 powershell 集成控制台
并运行以下脚本,它可以正常工作:
cd "d:\git\ITWeiHanDEV\Java\" && javac Demo.java && java Demo
英文:
I tried to change vscode terminal type to cmd
not powershell integrated console
and run below script and it's work
cd "d:\git\ITWeiHanDEV\Java\" && javac Demo.java && java Demo
答案2
得分: 2
PowerShell 6.x 及更早版本,包括 Windows PowerShell,不支持 &&
和 ||
,管道链操作符 - 它们仅在 PowerShell [Core] 7+ 中可用。
在 6.x 及更早版本中,您可以模拟 &&
的行为如下:
javac Demo.java; if ($LASTEXITCODE -eq 0) { java Demo }
英文:
PowerShell versions 6.x and earlier, including Windows PowerShell, do not support &&
and ||
, the pipeline chain operators - they're only available in PowerShell [Core] 7+
In 6.x and earlier, you can emulate the behavior of &&
as follows:
javac Demo.java; if ($LASTEXITCODE -eq 0) { java Demo }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论