1

for the life of me I can't figure out how to convert this batch file to powershell. The java line is where I have the problems - I don't know how to insert environment variables correctly into it.

@echo off
SET runDir=../../../
java -cp %runDir%*;%runDir%lib/* helper.colors.AnsiColorKt
pause

Does anyone know how to do it?

Please note, the java application must run within the powershell window, not an old-school Windows command prompt

4
  • It's not clear if this variable is required for the Java application itself. If it's not then you can easily replace it with a string.
    – montonero
    Feb 7, 2019 at 7:56
  • yes that is my question, how do I replace that? I tried various ways but couldn't get it to work ... however I'm new to powershell. I tried $var or ${var} - the problem is that there is text immediately after what I want to replace.. and I wasn't sure if I need to enclose any of the arguments with strings - and if so, what parts
    – Mikey
    Feb 7, 2019 at 8:15
  • the windows batch file runs fine - it might look "not efficient" because actually I have multiple files a run.bat with the java stuff and other files that call it setting the environment variable first..however to make things easier to understand, I combined it into a more-or-less-minimum-whatchamacallit (term from stackoverflow) here
    – Mikey
    Feb 7, 2019 at 8:18
  • probably you're looking for gradle? Although, who knows, maybe writing gradle build files in powershell is the way to go...
    – Thufir
    Jan 30, 2020 at 8:06

2 Answers 2

2

Replace it literally: java -cp ../../../*;../../../lib/* helper.colors.AnsiColorKt or if you want to use a powershell variable

$rundir="../../../"
java -cp "$rundir*;$($rundir)lib/*" helper.colors.AnsiColorKt
1
  • thanks, maybe the problem was that I was trying to use $env:runDir directly.. so now I did $rundir=$env:runDir and it works - or maybe just I wasn't using the correct syntax for ${$var)
    – Mikey
    Feb 7, 2019 at 8:45
0
set-item -path Env:CLASSPATH -value C:\mytest 
java.exe -classpath $Env:CLASSPATH myApp

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .