Edit file in ms-dos

狂风中的少年 提交于 2019-12-12 05:29:09

问题


Can this be done?

Basically I work on multiple projects using xampp, and I like http://localhost to be the project root ( rather than http://localhost/project_name/ )

Problem is, i have to open the httpd.conf file in the apache folder, change the document root, then restart apache!

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

Then all i would need to do is open the cmd prompt, and write:

http_change.bat new_project_name

Problem is, I only know basic ms-dos and examples and tuition on the web are surprising hard to understand!

EDIT

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
)

and that worked. then

for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do (
    set line=%%a
    echo %line%
)

and that failed... it just echoed "ECHO is off." which makes me assume the it isnt setting the line variable...

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...


回答1:


You're causing yourself unnecessary grief by trying to edit the configuration file. Here's a better idea:

  • Remove the DocumentRoot setting from your httpd.conf file. Replace it with an Include directive, something like:

    Include \path\to\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
    

And here's another idea:

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'



回答2:


I can't tell you how to:
1. find the directory with batch, or, 2. start/stop apache
but I can tell you how to edit it.
If you use XP or before, use
edit <drive:\path\file.ext>,
And if you use anything 64bit, or Vista or later, use
copy con <drive:\path\file.ext>
becuase the 16-bit edit application was removed from 64-bit versions of Windows.



来源:https://stackoverflow.com/questions/9906189/edit-file-in-ms-dos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!