• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can pipe cmd commands to powershell with "cmd /C" but not with "cmd /C start cmd /K"  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm using the below runtime command :




This works fine. I can pipe the powershell file from cmd.

When I run this however :



It Just runs the type command and prints the output In the window. It's not getting piped to powershell.

I need to use the second method because I want the user to see the output.

Not sure what's going wrong here and would appreciate any Info.

Thanks.
 
Tim Moores
Saloon Keeper
Posts: 4034
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't help with the Windows stuff, but the first thing I would do is to switch from Runtime.exec(String) to Runtime.exec(String[]). That avoids quite a few pitfalls of Runtime.exec. Even better, use the ProcessBuilder class instead.
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not certain, but I think the pipe operator has lower precedence than juxtaposition, so you're piping the output of "cmd start" into powershell, not the output of "cmd type".

It appears you use start to spawn a new window for the output of powershell. Instead of doing "cmd /C start cmd /K type", why don't you just do "cmd /K type"?
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
In reply to Stephan van Hulst ,

If I use only cmd /K there Is no output appearing. It works but I need to show the output from the cmd.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!