File read issues after modification

8 posts in this topic

m1975michael 0

I have been writing a script to backup computers. Part of the script requires running a batch file as eventually it will be a scheduled job in Windows. The script works unless I modify the batch file during the running of the script. The only thing I am changing is line one in the batch file so that it reflects a proper IP address for that location. I do not understand why this is not working any suggestions would be greatly appreciated.

Share this post

Link to post

Share on other sites

m1975michael 0

Isn't if a program is already opened it can't be opened by another file?

You'll need to wait to modify it till its either closed or the script has already ran.

At least I'm pretty sure, as this is what I understood your question to be.

The script opens the batch file, modifies the first line then closed the file. Then batch file is executed.

The script works fine if I don't modify the batch file but it is necessary to modify the batch file because each of the location IP addresses are different. I am not sure why it should make a difference as I am opening, modifying and closing the file before the execution of the batch file. Any ideas?

Share this post

Link to post

Share on other sites

BrewManNH 971

Why are you using a batch file when you can do everything from within your script?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Share this post

Link to post

Share on other sites

m1975michael 0

Why are you using a batch file when you can do everything from within your script?

There are certain commands that don't work when you are not in an interactive session. ie Task Scheduler job but using third partly software. I can't "open" a command window and send commands when the session is not interactive. A batch file allow the commands to be executed without opening command window.

Share this post

Link to post

Share on other sites

BrewManNH 971

There's no need to open a command window and send commands to one, use the run command with @ComSpec and keep it hidden (only use @SW_HIDE AFTER you've determined that your commands work as intended). This will work in an interactive or non-interactive session.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Share this post

Link to post

Share on other sites

m1975michael 0

There's no need to open a command window and send commands to one, use the run command with @ComSpec and keep it hidden (only use @SW_HIDE AFTER you've determined that your commands work as intended). This will work in an interactive or non-interactive session.

I will try it again TY.

Share this post

Link to post

Share on other sites

guinness 1,430

AutoIt is basically superior than batch scripting tenfold. Okay you have to invest a little bit of time learning, but when you do you'll appreciate just how quick it is to bang out a script than do it manually yourself.