powershell'<'运算符保留供将来在Java中使用 [英] powershell The '<' operator is reserved for future use in Java

查看:103
本文介绍了powershell'<'运算符保留供将来在Java中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关此问题的答案,但没有发现两个文件之间的比较,实际上这是基于 BinarySearch 的《 算法》一书的示例,这是源代码

I've read many answers about this question but nothing was found about the comparison between two files, actually this is a sample of the book Algorithms based on BinarySearch, here is the source code

import java.util.Arrays;
import edu.princeton.cs.algs4.*;

public class prac1_1_23{

public static boolean BinaryLookup(int key, int[] arr) {
    int low = 0;
    int high = arr.length - 1;
    while(low <= high) {
        int mid = low + ((high - low) >> 1);
        if(key < arr[mid])
            high = mid - 1;
        else if(key > arr[mid])
            low = mid + 1;
        else
            return true;
    }
    return false;
}

public static void main(String[] args) {
    char symbol = '-';
    int[] whitelist = new In(args[0]).readAllInts();
    Arrays.sort(whitelist);
    while(!StdIn.isEmpty()) {
        int key = StdIn.readInt();
        boolean found = BinaryLookup(key, whitelist);
        if('+' == symbol && !found)
            StdOut.println(key);
        if('-' == symbol && found)
            StdOut.println(key);
    }
}
}

此示例使用了一个由该书的作者撰写,可以通过算法进行访问,问题是我何时想通过Windows的 PowerShell 运行该程序,例如命令

This sample utilizes a library made by the author of the book, which can be accessed via Algorithms, and the question is when I want to run this program via the PowerShell of windows,like the command

java prac1_1_23 largeW.txt < largeT.txt

我遇到了类似
错误

实际上我找到了运行此代码的解决方案,但没有用要在PowerShell上解决该问题,需要我使用本书作者编写的命令行程序,该程序可以在 algs4.cs.princeton.edu/windows/网站上下载,并且需要编译和运行该程序像

actually I find a solution to run this code but is useless to solve it on PowerShell which requires me to use the commandline program written by the author of this book which can be download on the website of "algs4.cs.princeton.edu/windows/", and it need to compile and run the program with the commandline like

javac-algs4 prac1_1_23.java    //compile command

java-algs4 prac1_1_23 largeW.txt < largeT.txt   //run command

它确实有效,但是我想知道我们是否可以利用原始的CLI,因为我发现有人可以在Linux操作系统上运行原始代码而没有任何问题。

it does work but I wonder if we can utilize the original CLI because I found someone can run the original code on the Linux operating system without problems.

任何帮助都表示感谢,谢谢。

Any help is appreciated, thank you.

推荐答案

您是否尝试使用-%运算符为重定向添加前缀?例如:

Have you tried prefixing the redirection with the --% operator? For example:

   cmd /c --% java prac1_1_23 largeW.txt < largeT.txt

上面的命令为您的命令添加了三件事,让我解释一下:

The command above prefixes your command with three things, let me explain them:


  • cmd 调用cmd.exe,它知道<$ c是什么意思$ c><

  • cmd invokes cmd.exe, which knows what you mean by <

/ c 告诉cmd.exe要在命令行中处理以下命令,然后退出。

/c tells cmd.exe to process one command following on the command line and then exit.

-%告诉PowerShell离开命令行的其余部分,以便cmd.exe可以处理< 重定向。

--% tells PowerShell to leave the rest of the command line alone, so that cmd.exe can deal with the < redirection.

这种方式您不需要命令脚本。

This way you don't need a command script.

这篇关于powershell'&lt;'运算符保留供将来在Java中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆