Package hudson.os

Class WindowsUtil

java.lang.Object
hudson.os.WindowsUtil

public class WindowsUtil extends Object
Utilities for the Windows Platform. Adapted from: Everyone quotes command line arguments the wrong way
Since:
2.183
  • Constructor Details

    • WindowsUtil

      public WindowsUtil()
  • Method Details

    • quoteArgument

      @NonNull public static String quoteArgument(@NonNull String argument)
      Quotes an argument while escaping special characters interpreted by CreateProcess.
      Parameters:
      argument - argument to be quoted or escaped for windows shells.
      Returns:
      properly quoted and escaped windows arguments.
    • quoteArgumentForCmd

      @NonNull public static String quoteArgumentForCmd(@NonNull String argument)
      Quotes an argument while escaping special characters suitable for use as an argument to cmd.exe.
      Parameters:
      argument - argument to be quoted or escaped for cmd.exe.
      Returns:
      properly quoted and escaped arguments to cmd.exe.
    • execCmd

      @NonNull public static Process execCmd(String... argv) throws IOException
      Executes a command and arguments using cmd.exe /C ....
      Parameters:
      argv - arguments to be quoted or escaped for cmd.exe /C ....
      Returns:
      properly quoted and escaped arguments to cmd.exe /C ....
      Throws:
      IOException
    • createJunction

      @NonNull public static File createJunction(@NonNull File junction, @NonNull File target) throws IOException, InterruptedException
      Creates an NTFS junction point if supported. Similar to symbolic links, NTFS provides junction points which provide different features than symbolic links.
      Parameters:
      junction - NTFS junction point to create
      target - target directory to junction
      Returns:
      the newly created junction point
      Throws:
      IOException - if the call to mklink exits with a non-zero status code
      InterruptedException - if the call to mklink is interrupted before completing
      UnsupportedOperationException - if this method is called on a non-Windows platform