Sinisterly
[Batch] Help w/ Wierd Spacing Issue - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: [Batch] Help w/ Wierd Spacing Issue (/Thread-Batch-Help-w-Wierd-Spacing-Issue)

Pages: 1 2


[Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-04-2014

Hey guys so right now I'm working on a really basic messenger system that can be used anywhere with open network locations such as a shared drive like those in schools.

Before I explain what the issue is, I thought it might be helpful to explain how the program works.

-User starts up a start-up batch program which starts by checking for a username.txt file in a folder labeled Data in the compressed folder that the messenger comes in.

[Image: qilv.png]

- If a username exists, it asks the user if they would like to change it.
- Otherwise it prompts the user to create a Username.

- Then it asks for a file location for the chat-room to be placed in or where it already exists and then runs a window for the sender and one for the receiver.

The issue comes when the User's name appears...
At first its normal, but if they choose to not change their username it adds extra space each and every time they start the program again.

I will link the three programs in text form so none of you get paranoid. Tongue

[attachment=103]

Please let me know why if you figure it out!

P.S. Go easy on me I'm just a Script Kiddie and I really only have some better-than-basic skills in Batch.


RE: [Batch] Help w/ Wierd Spacing Issue - Satan - 03-04-2014

(03-04-2014, 02:37 AM)DarkMuse Wrote: Hey guys so right now I'm working on a really basic messenger system that can be used anywhere with open network locations such as a shared drive like those in schools.

Before I explain what the issue is, I thought it might be helpful to explain how the program works.

-User starts up a start-up batch program which starts by checking for a username.txt file in a folder labeled Data in the compressed folder that the messenger comes in.

[Image: qilv.png]

- If a username exists, it asks the user if they would like to change it.
- Otherwise it prompts the user to create a Username.

- Then it asks for a file location for the chat-room to be placed in or where it already exists and then runs a window for the sender and one for the receiver.

The issue comes when the User's name appears...
At first its normal, but if they choose to not change their username it adds extra space each and every time they start the program again.

I will link the three programs in text form so none of you get paranoid. Tongue



Please let me know why if you figure it out!

P.S. Go easy on me I'm just a Script Kiddie and I really only have some better-than-basic skills in Batch.

For some reason when I tried to recreate these without using anything beyond what dealt with the name, it wouldn't find the Txt file after playing with it a bit too much.

I did recreate your issue, however.
Playing around, I did find that removing the spacing where it adds to the file itself does stop it from adding additional spaces if it wasn't changed, but it doesn't save the name, which may be unrelated.

My guess is you're reading the text file and storing it as variable %name%, then somewhere in your code, resaving it with %name%[Space], which would then make the name when it restarts, E.g. "Satan", do this:
Starts, Loads "Satan".
Does not change username, resaves "Satan[Space]".
Restarts, Loads "Satan[Space]".
Does not change username, resaves "Satan[Space][Space]"

I'd look for something that may be doing that.

Played with too much to try to get it working with a super stripped down recreation, and broke it somehow, so be careful with it.


RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-04-2014

(03-04-2014, 06:12 AM)Satan Wrote: For some reason when I tried to recreate these without using anything beyond what dealt with the name, it wouldn't find the Txt file after playing with it a bit too much.

I did recreate your issue, however.
Playing around, I did find that removing the spacing where it adds to the file itself does stop it from adding additional spaces if it wasn't changed, but it doesn't save the name, which may be unrelated.

My guess is you're reading the text file and storing it as variable %name%, then somewhere in your code, resaving it with %name%[Space], which would then make the name when it restarts, E.g. "Satan", do this:
Starts, Loads "Satan".
Does not change username, resaves "Satan[Space]".
Restarts, Loads "Satan[Space]".
Does not change username, resaves "Satan[Space][Space]"

I'd look for something that may be doing that.

Played with too much to try to get it working with a super stripped down recreation, and broke it somehow, so be careful with it.

Yeah its strange it does that weird looping thing where it doesn't find the specific path for the chat idk why. Basically it works so I'll just have to keep picking at it piece by piece.
Thanks for the advice!


RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-22-2014

It seems pretty obvious to me, and anyone who has much experience with batch would be able to guess the error, I just had to find the line, but based on your explanation:
Code:
ECHO %name% > %cd%\Data\UsernameData.txt

It's here...

Remove the space you are adding:
Code:
ECHO %name%> %cd%\Data\UsernameData.txt



Re: RE: [Batch] Help w/ Wierd Spacing Issue - Satan - 03-23-2014

(03-22-2014, 03:54 AM)0xDEAD10CC Wrote: It seems pretty obvious to me, and anyone who has much experience with batch would be able to guess the error, I just had to find the line, but based on your explanation:
Code:
ECHO %name% > %cd%\Data\UsernameData.txt

It's here...

Remove the space you are adding:
Code:
ECHO %name%> %cd%\Data\UsernameData.txt

When I tested that before my original response to this thread, it resaved the name as "ECHO is on" in the text file.


RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014

(03-23-2014, 12:08 AM)Satan Wrote: When I tested that before my original response to this thread, it resaved the name as "ECHO is on" in the text file.

Then %name% wasn't assigned any value, and @echo off was never encountered at that time, simple.


Re: RE: [Batch] Help w/ Wierd Spacing Issue - Satan - 03-23-2014

(03-23-2014, 12:10 AM)0xDEAD10CC Wrote: Then %name% wasn't assigned any value, simple.

It would be assigned on first run. Saves correctly. Second run if it was then not changed* it would resave it to that.


Correcting error


RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014

Idk but now it wont create any of the temp text files on my laptop but im thinking it might br a security setting with windows 8? Ideas?


RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014

(03-23-2014, 12:12 AM)Satan Wrote: It would be assigned on first run. Saves correctly. Second run if it was then not changed* it would resave it to that.


Correcting error

I didn't look at the entire script, I narrowed it down by what he explained was happening that shouldn't. This is exactly what is happening:
Quote:echo something{space}> output.txt

That space shouldn't be in there.

If you're getting an output of "ECHO is on", then either %name% has been saved to that, YOU mistyped the variable name, or it was never set. There are no other reasons, I know my batch scripting.

@both - Provide the code in code tags as to what you've both tried. I'm not downloading any more zip files for a bit of text, it's not necessary. I'll show you what's happening.


Re: RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014

(03-23-2014, 01:43 AM)0xDEAD10CC Wrote: I didn't look at the entire script, I narrowed it down by what he explained was happening that shouldn't. This is exactly what is happening:

That space shouldn't be in there.

If you're getting an output of "ECHO is on", then either %name% has been saved to that, YOU mistyped the variable name, or it was never set. There are no other reasons, I know my batch scripting.

I know sometimes DOS doesnt like writing to files while in an if conditional, could that be it?