ankushbhardwxj / codemon

cli to win programming contests
https://pypi.org/project/codemon/
MIT License
26 stars 12 forks source link

Not working on windows platform with cmd #21

Closed lucifer0987 closed 3 years ago

lucifer0987 commented 3 years ago

"." is not a recognized command. It gives this error on windows platform after compilation when we run the executable of cpp file.

lucifer0987 commented 3 years ago

Can you please take a look and approve it? And, if approved, I would like to work on it.

paramsiddharth commented 3 years ago

I can fix that issue and would like to work on this. Could you assign it to me?

lucifer0987 commented 3 years ago

I am already working on this and kind of fixed this. Thats why, I created this issue. I was just waiting for @ankingcodes nod. Really sorry for this confusion @paramsiddharth .

ankushbhardwxj commented 3 years ago

@lucifer0987 - can you send a screenshot of this issue ? Also, specify which terminal are you using ? I'm using WSL2 so I don't get this error.

ankushbhardwxj commented 3 years ago

@paramsiddharth - since @lucifer0987 has filed the issue and wants to work on it, I think he should be given the first chance to work on it. Feel free to make a PR if he doesn't.

lucifer0987 commented 3 years ago

@lucifer0987 - can you send a screenshot of this issue ? Also, specify which terminal are you using ? I'm using WSL2 so I don't get this error.

I am working on windows 10 and I am using CMD. when we run the prog file with input, then we are using '.', I think that is creating the issue. and writing different codes for different OS will resolve it. Screenshot (516)

ankushbhardwxj commented 3 years ago

It's not supposed to compile prog.exe in anyway, we are only supposed to compile A.cpp by doing g++ A.cpp -o prog and then do ./prog < input.txt. I believe the reason we are getting this error is because of using ./prog < input.txt which is valid on UNIX but not on Windows.

You may send a PR for this but make sure the program distinguishes the platform and then performs ./prog < input.txt or anything else (not an CMD user so not sure what should it do).

paramsiddharth commented 3 years ago

It's not supposed to compile prog.exe in anyway, we are only supposed to compile A.cpp by doing g++ A.cpp -o prog and then do ./prog < input.txt. I believe the reason we are getting this error is because of using ./prog < input.txt which is valid on UNIX but not on Windows.

You may send a PR for this but make sure the program distinguishes the platform and then performs ./prog < input.txt or anything else (not an CMD user so not sure what should it do).

It is actually the concept of PATHEXT that distinguishes executables in Windows/DOS from UNIX/GNU systems. I understand you are using WSL2 but the traditional Windows user has access only to the Command Prompt and PowerShell. A tiny OS-agnostic edit is needed which will fix the bug.

lucifer0987 commented 3 years ago

It's not supposed to compile prog.exe in anyway, we are only supposed to compile A.cpp by doing g++ A.cpp -o prog and then do ./prog < input.txt. I believe the reason we are getting this error is because of using ./prog < input.txt which is valid on UNIX but not on Windows.

You may send a PR for this but make sure the program distinguishes the platform and then performs ./prog < input.txt or anything else (not an CMD user so not sure what should it do).

Yeah, you are right. What's happening here is, the code is listening for changes and as soon as we change "A.cpp", it is compiled, and prog.exe is generated and its also changed. But, our program doesn't exclude "prog.exe", its only excluding "prog". Here, by excluding, I mean the files which won't be considered for changes. And, since it detects "prog.exe" as a changed file. It tries to compile that also. As a result we get, the second error "g++ : fatal error". So, we have to fix 2 things here. First, we have to make our program exclude "prog.exe" and "prog" both. Second, we have to write OS-specific codes for running the "prog" file with "input.txt". We can fix this as @paramsiddharth said.

ankushbhardwxj commented 3 years ago

Thanks @lucifer0987 & @paramsiddharth for explaining. You may proceed with a PR for this.

paramsiddharth commented 3 years ago

I have made a PR with the fix I had in mind. I used the standard OS-agnostic way of traversing the file(s), instead of explicitly distinguishing between the OSes and executing a different command for each. Let me know what you think, @ankingcodes.

lucifer0987 commented 3 years ago

@ankingcodes

C:\Users\Gaurav Kumar\Desktop\round-684>codemon listen
Getting files in directory
Currently listening for file changes

Change made at A.cpp

Compiling A.cpp
Running
Taking inputs from input.txt
'C:\Users\Gaurav' is not recognized as an internal or external command,
operable program or batch file.

Change made at A.cpp

Compiling A.cpp
Running
Taking inputs from input.txt
'C:\Users\Gaurav' is not recognized as an internal or external command,
operable program or batch file.

I am talking in reference to windows OS. Its happening because, in the current code, we are getting the current working directory and then compiling the file present in that directory. But, if the directory contains whitespaces, it creates error, its not able to recognize the directory. Maybe, @paramsiddharth didn't check this and thats why he didn't get any error.

After fix :-

C:\Users\Gaurav Kumar\Desktop\round-684>codemon listen
Getting files in directory
Currently listening for file changes

Change made at A.cpp

Compiling A.cpp
Running
Taking inputs from input.txt
7
5
Changed CPP file compiled and run. Check output.

Change made at A.cpp

Compiling A.cpp
Running
Taking inputs from input.txt
7
5
Changed CPP file compiled and run. Check output.

I have created a PR with the fixed code. #31