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

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

问题描述

有人说,他们的路径太长,然而,问题往往是由同样的批处理脚本反复调用导致与code像集mypath中=%mypath中%;附录人们只是没有意识到。我提出了一个搜索解决方案ñ退出时恢​​复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?

我们可以用智能附录开始。我的意思是,这个问题是由无条件附加的路径而引起的。你已经有你的路径上的阑尾却一遍遍重新添加。这是问题的根源。我认为同样的问题适用于抨击。可能是我可以检查路径和只添加那些缺失的条目?标准的解决方案是什么?

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?

推荐答案


首先,你的code不能正常工作,例如, 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%

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

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