Jump to content

Batch file problems...


Recommended Posts

Hi,

I'm working on a batch file that alters the contents of a couple of text files as part of its operation. I use the "Fedit" utility (picked it up from Bashrat's Driver Packs) to edit the text.

I'm having a problem editing a couple of lines of text that contain escape characters. I do not know if there's an easy way round this, but since my batch file expertise is far more limited than some people's around here I thought I'd try begging!

Here is the pertient part of the text file that will be edited:

...
%CD%\FILES\ROBOCOPY "%FOLDER%" "%UWXPCD%" *.* /E %RS%
...

Here is an example of the type of batch file operation that is causing me hassle:

FEDIT -ADD -ONCE -F %BTS%\textfile.cmd -A "%CD%\FILES\ROBOCOPY "%FOLDER%" "%UWXPCD%" *.* /E %RS%" -L "%RUNFROM%\FILES\ROBOCOPY "%FOLDER%" "%UWXPCD%" *.* /E %RS%"

The syntax of Fedit expects:

FEDIT -ADD -ONCE -F <filename> -A "<line of text>" - L "<line of text>"

The operation should result in the text following -L to be added directly underneath the line following -A

The problem appears to be the prescence of % and " in the command line. I've tried removing the extra quotes, using /" and /% but nothing works correctly.

Does anyone have a way around this?

Thank you,

Andy

Edited by Fencer128
Link to comment
Share on other sites


Hi Chad,

Thanks for the info. Using the command line you supplied has 2 effects:

1. The correct text is entered into the text file.

2. The text is entered at the end of the file, rather than directly after the line referenced by the -A switch. I suspect this is to do with the way in which fedit parses "%%CD%%\FILES\ROBOCOPY "%%FOLDER%%" "%%UWXPCD%%" *.* /E %%RS%%" with the extra escape characters in it. Now, if the extra %s are removed then the command fails with a syntax error.

I guess I still need to work on point 2.

Thanks again,

Andy

Edited by Fencer128
Link to comment
Share on other sites

I think it might be more likelly that the inner quotes are the problem.

I'm curious what happens if you do this...

echo exit| command /kPrompt -ADD -ONCE -F %BTS%\textfile.cmd -A %%CD%%\FILES\ROBOCOPY$S"%%FOLDER%%"$S"%%UWXPCD%%"$S*.*$S/E$S%%RS%% -L %%RUNFROM%%\FILES\ROBOCOPY$S"%%FOLDER%%"$S"%%UWXPCD%%"$S*.*$S/E$S%%RS%% | FEDIT

Chad

Edited by cmarcusson
Link to comment
Share on other sites

Hi Chad,

I tried it and got:

"The system cannot execute the specified program".

I don't know if I've done something wrong or if the command line just won't work that way.

Thanks again,

Andy

EDIT: Should have also said, not sure it's that important, but trying the first method you posted also resulted in the "" being missing from around %FOLDER% and "%UWXPCD% that were added to the bottom of the text file. Thanks.

Edited by Fencer128
Link to comment
Share on other sites

It just occured to me that the command tail length for this command is way too long. We max out at 127 Bytes after any given command, since the data is inserted at 0x81h and the program will start at 0x100h. I would venture to say that this particular approach is not going to work. There are other oossible alternatives methodes though.

Chad

Link to comment
Share on other sites

Hi,

If I use this:

FEDIT -ADD -ONCE -F %BTS%\BTS_DPs_auto.example.cmd -A "%%CD%%\FILES\ROBOCOPY \"%%FOLDER%%\" \"%%UWXPCD%%\" *.* /E %%RS%%" -L "%%RUNFROM%%\FILES\ROBOCOPY "%%FOLDER%%" "%%UWXPCD%%" *.* /E %%RS%%"

and insert / before " then I can get the text placed in the correct place. The only small issue remaining now is if it is possible to keep the "" around the variables in the pasted text...

EDIT:

Escaping the " in the text to be pasted as is done above for the searched for text gets the job done 100%

FEDIT -ADD -ONCE -F %BTS%\BTS_DPs_auto.example.cmd -A "%%CD%%\FILES\ROBOCOPY \"%%FOLDER%%\" \"%%UWXPCD%%\" *.* /E %%RS%%" -L "%%RUNFROM%%\FILES\ROBOCOPY \"%%FOLDER%%\" \"%%UWXPCD%%\" *.* /E %%RS%%"

Solved! :thumbup

Cheers,

Andy

Edited by Fencer128
Link to comment
Share on other sites

I'm sorry I couldn't help earlier, I can't check the forums much anymore because of a vacation job. Glad you solved your problem. You may want to check the new fedit, wich works better, and has extra features :D

Also, don't forget quotes around the filename (for if ever the file to be edited is in a dir with spaces in it's name):

EDIT -ADD -ONCE -F "%BTS%\BTS_DPs_auto.example.cmd" -A "%%CD%%\FILES\ROBOCOPY \"%%FOLDER%%\" \"%%UWXPCD%%\" *.* /E %%RS%%" -L "%%RUNFROM%%\FILES\ROBOCOPY \"%%FOLDER%%\" \"%%UWXPCD%%\" *.* /E %%RS%%"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...