路径初始化:防止“输入行太长” [英] Path initialization: preventing “The input line is too long”

查看:191
本文介绍了路径初始化:防止“输入行太长”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些人说他们的路径太长,但是,这个问题常常是由于同一个批处理脚本的重复调用引起的代码如 set mypath =%mypath%;附录人们根本没有意识到这一点。我提出了一个解决方案 n在退出时恢复env变量

Some people say that their path is too long, However, the problem is often caused by recurring call of the same batch script with code like set mypath=%mypath%;appendix. People just do not realize that. I proposed a solution to restore the env variables upon exit

set old_path=classpath
set classpath=%classpath%;appendix
java myApp
set classpath=old_path

但是这很麻烦,容易出错。我可能很容易忘记恢复或失败,由于异常,另一个退出路径。这可以自动完成吗?

But it is tedious and error prone. I may easily forget to recover or fail due to exception, another exit path. Can this be done automatically?

我们可以从智能附录开始。我的意思是问题是无条件地追加路径引起的。您的路径上已经有附录,但是一遍又一遍地添加。这是问题的根源。我认为同样的问题适用于bash。可能我可以检查路径,只添加那些缺少的条目吗?什么是标准解决方案?

We can start with a smart appendix. I mean that the problem is caused by appending the path unconditionally. You already have the appendix on your path but add it over and over again. That is the root of the problem. I think that the same problem applies to bash. Might be I can check the path and add only those entries which are missing? What is the standard solution?

推荐答案


首先,您的代码无法工作,例如 old_path 是您最后一个命令中的一个字符串。

first, your code can't work, e.g. old_path is a string in your last command.

set "old_path=%classpath%"
set "classpath=%classpath%;%appendix%"
java myApp
set "classpath=%old_path%"

第二,只需在批量中使用一个新的环境来避免这样的问题:

second, just use a new environment in the batch to avoid such issues:

@echo off
echo %path%
setlocal
set "path="
echo %path%
endlocal
echo %path%

这篇关于路径初始化:防止“输入行太长”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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