Is no need anymore using of OpenConsole() .. output inside cmd.exe : d o n e

Windows specific forum
xpectmore
User
User
Posts: 15
Joined: Thu Jul 29, 2021 12:52 pm

Is no need anymore using of OpenConsole() .. output inside cmd.exe : d o n e

Post by xpectmore »

Code: Select all

;thank you
;to this guy https://titanwolf.org/Network/Articles/Article?AID=afa0bc13-b32a-48f3-96d0-6b90cf8c9b75#gsc.tab=0
;now this compiled as console
;if run it in console will output inside the console 
;you do not need openconsole() anymore
;thank you Priya !!!
;
ImportC "msvcrt.lib"
  system(str.p-ascii)
EndImport
;system("setlocal enabledelayedexpansion")
system("echo salut")


and

Code: Select all

ImportC "msvcrt.lib"
  system(str.p-ascii)
EndImport
;system("setlocal enabledelayedexpansion")

Procedure say(text.s)
  system("echo "+text)
EndProcedure


say(" Hello from PureBasic ,the best!")

:mrgreen:
ps.now i see the .exe 's size is 6kb !!!!! yahooooo
without this will not work: compiler -> compiler options -> Executable format: console
by removing the option
Enable modern theme support(for Windows XP and above) the .exe size drop to 5kb !!!

I tested fine in 5.73 LTS x64 and the new one.. the 6.00 alpha 3 x64 !
// Edit: Topic title adapted. @xpectmore: Please avoid writing everything in capital letters and do not use too many exclamation marks.






using compiler -> compiler options -> Executable format: console the same with this the system waiting to press a key :

Code: Select all

Procedure run(cmd.s)
  RunProgram("c:\windows\system32\cmd.exe", "/c"+cmd, "")
EndProcedure


run("echo I have something to say you")
the exe is about 7.6kb and if i runt this directly the console disappear(only compiled had the effect i described)





new test success :

Code: Select all

Procedure say(cmd.s)
  cmd2.s="echo "+cmd;cmd2.s=UnescapeString("echo "+cmd)
  test=RunProgram("c:\windows\system32\cmd.exe", "/c"+cmd2, "",#PB_Program_Open  | #PB_Program_Connect)
  If test
    While ProgramRunning(test)
        WriteProgramStringN(test,cmd2,#PB_Ascii  )
    Wend   
    CloseProgram(test)
  EndIf
EndProcedure

say("I have something to say you")
say("do not learn c/c++/c# : you have PureBasic")



not the answer of his question (TheCube ) but the hide method to run using same settings compiler -> compiler options -> Executable format: console:

Code: Select all

Procedure system(cmd.s)
  RunProgram("c:\windows\system32\cmd.exe", "/K"+cmd, "", #PB_Program_Hide)
EndProcedure


system("echo i write this hidden> purebasic.txt")
system("echo do not learn c/c++/c# : you have PureBasic>> purebasic.txt")

so compiled .exe[s] on the destop i check 3 of these (the hidden version too) inside virustotal.com and at the moment the result was:
not even a false positive virus witch is GREAT !!!
Last edited by xpectmore on Sun Aug 01, 2021 10:27 am, edited 7 times in total.
User avatar
TheCube
New User
New User
Posts: 5
Joined: Sat Jul 31, 2021 2:00 pm

Re: Is no need anymore using of OpenConsole() .. output inside cmd.exe : d o n e

Post by TheCube »

Nice for small quick debug outputs. 8)
But ... how can I close the console during runtime without CloseConsole() ?

But maybe ist a senseless question, i think about a background application (no window outside of startup or problems)
xpectmore
User
User
Posts: 15
Joined: Thu Jul 29, 2021 12:52 pm

Re: Is no need anymore using of OpenConsole() .. output inside cmd.exe : d o n e

Post by xpectmore »

in the past(only if you search in this forum) we experienced problems to output in cmd.exe so we was in some cases we were obliged to use of OpenConsole .So what you read here is design only when you really need tou output (eg your command inside the cmd.exe ). if you study the manual the language has already the possibility to run hidden -see perhaps RunProgram #PB_Program_Hide and in this case even isn't any reasons to hide that console you can hide it by combining what i provide you earlier and structuring your program by ProgramParameters and CountProgramParameters schema ; eg:
your shell command program is demo.exe so internal you check is CountProgramParameters zero so you can run the same program with RunProgram hide .. dem.exe -hide and internal the parameter "-hide" you put there what you used until my post.
so that trick i discover from that guy isn't only for debug it can be used when you really need to output in cmd.exe and to see the resutls inside.

partial results to output in cmd.exe i obtined by using "RunProgram" but is outputing without crlf and if i add crlf had no effect so i am convinced not 100% what i adapt from the script of that guy is doing the result i expected but something in the new windows 10 21H1 x64 api .

anyone know to improve that is free to do it : i don't know c(even i do want to know c -for this i bought purebasic even i had freebasic too) or windows api maybe someone knows and can find out what really happened so we was able to output. the same person maybe knows how to hide it and in this case,at this point, all my speech above it makes no sense anymore..
and if you visit https://titanwolf.org/Network/Articles/ ... #gsc.tab=0 (the original example) you see he/she uses OpenConsole maybe he/she doesn't even know with that compiler option you can manage these results...


a possible answer is this
https://social.msdn.microsoft.com/Forum ... =vcgeneral

"Use ShellExecute or CreateProcessEx to do this. Both of those let you have a hidden window."
User avatar
TheCube
New User
New User
Posts: 5
Joined: Sat Jul 31, 2021 2:00 pm

Re: Is no need anymore using of OpenConsole() .. output inside cmd.exe : d o n e

Post by TheCube »

Thank you for the detailed explanations and the additions to your first post. :D
I'll play around a bit more, let's see what I'll need it for.
Post Reply