路径初始化:防止“输入行太长”

编程入门 行业动态 更新时间:2024-10-23 08:37:21
本文介绍了路径初始化:防止“输入行太长”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有些人说他们的路径太长,但是,这个问题常常是由于同一个批处理脚本的重复调用引起的代码如 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%

更多推荐

路径初始化:防止“输入行太长”

本文发布于:2023-07-14 22:03:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   太长   路径

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!