在MS-DOS编辑文件 [英] Edit file in ms-dos
问题描述
可以这样做?
基本上我在多个项目使用XAMPP,我喜欢的http://本地主机
是项目的根(而不是 HTTP:/ /本地主机/ PROJECT_NAME /
)
Basically I work on multiple projects using xampp, and I like http://localhost
to be the project root ( rather than http://localhost/project_name/
)
问题是,我不得不打开apache的文件夹中的httpd.conf文件,更改文档根目录,然后重新启动Apache!
Problem is, i have to open the httpd.conf file in the apache folder, change the document root, then restart apache!
我在想,如果这可以在MS-DOS办?
I was wondering if this could be done in ms-dos?
说我写一个批处理文件:
say I write a batch file that:
opens the file,
finds the document root,
changes it,
stop apache,
start apache
然后,所有我需要做的就是打开CMD提示,并写:
Then all i would need to do is open the cmd prompt, and write:
http_change.bat new_project_name
问题是,我只知道在网络上基本的MS-DOS和实例和学费是令人惊讶的很难理解!
Problem is, I only know basic ms-dos and examples and tuition on the web are surprising hard to understand!
修改
我真的与此这样的IM产品赏金挣扎。
I'm Really struggling with this so im offering a bounty.
到目前为止,我已经试过:
so far i've tried:
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do echo %%a
这成功读取该文件,但后来我试图
this successfully reads the file, but then i tried
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do (
echo %%a
)
和奏效。然后
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do (
set line=%%a
echo %line%
)
和失败......它只是回应的ECHO处于关闭状态。这使我假设它不是设置行变量...
and that failed... it just echoed "ECHO is off." which makes me assume the it isnt setting the line variable...
我的计划是要检查每一行,看看前12个字符==的DocumentRoot如果他们这样做,而不是保存行到一个新的文件,我修改使用蜇操纵线和保存,而不是..
my plan was to check each line to see if the first 12 characters == "DocumentRoot" and if they do, rather than saving the line to a new file, i modify the line using sting manipulation and save that instead...
推荐答案
您正试图通过编辑配置文件导致自己带来不必要的悲伤。这里有一个更好的主意:
You're causing yourself unnecessary grief by trying to edit the configuration file. Here's a better idea:
-
删除
的DocumentRoot
从的httpd.conf
文件中设置。与包含
指令代替它,是这样的:
Remove the
DocumentRoot
setting from yourhttpd.conf
file. Replace it with anInclude
directive, something like:
Include \path\to\documentroot.conf
现在,而不是编辑一个文件,你简单的替换 documentroot.conf
文件,其中包含以下形式的单行:
Now instead of editing a file you simple replace the documentroot.conf
file, which contains a single line of the form:
DocumentRoot \path\to\my\documentroot
和这里的另一个想法:
您可以通过Apache配置选项与 -C
指令在命令行上(或 -c
,视您是否希望之前应用的指令( -C
)或之后( -c
)的Apache读取它的配置文件) 。因此,作为与previous的想法,从你的的httpd.conf
,然后当你重新启动的httpd $ C $删除DocumentRoot指令C>,象这样开始:
You can pass Apache configuration options on the command line with the -C
directive (or -c
, depending on whether you want your directive applied before (-C
) or after (-c
) Apache reads its configuration files). So as with the previous idea, remove the DocumentRoot directive from your httpd.conf
, and then when you restart httpd
, start it like this:
httpd -C 'DocumentRoot \path\to\my\documentroot'
这篇关于在MS-DOS编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!