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

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

  • 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 '19 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 '19 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 '19 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 '20 at 8:06

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

java -cp "$rundir*;$($rundir)lib/*" helper.colors.AnsiColorKt
  • 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 '19 at 8:45
set-item -path Env:CLASSPATH -value C:\mytest 
java.exe -classpath $Env:CLASSPATH myApp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.