running an exe on batch...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

running an exe on batch...

#1 Post by TheHunterManX » 05 Oct 2015 07:06

I am having problems with my file. I want to make a server using ftp and I put all my data in the Cred.bat file, then converted it to an exe. However, when I run it using batch, It does nothing. I also do not want a temp file as it can be accessed if someone clicks it as it is being ran. Does someone know how to do this?
Example.exe content:
set p1=1
set p2=2
set p3=7
Example.bat content:
call Example.exe
echo %p1%
echo %p2%
echo %p3%
pause
what should happen on cmd:
1
2
7
press any key to continue...
What happens:
Echo is off
Echo is off
Echo is off
press any key to continue...

Please dont say use a temp file.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: running an exe on batch...

#2 Post by trebor68 » 07 Oct 2015 15:32

Your first file is running as following file:

Code: Select all

@echo off
setlocal
set p1=1
set p2=2
set p3=7
endlocal


Within around some variables are set. These variables are set in the converted file, but there is no output.

The following file File1.cmd an output that can be used in the other batch file continues to take place.
This file can converting to File1.exe.

Code: Select all

@echo off
setlocal
set p1=1
set p2=2
set p3=7

echo %p1% %p2% %p3%
endlocal


Here is File2.cmd:

Code: Select all

@echo off
setlocal ENABLEEXTENSIONS
for /f "tokens=1-3" %%a in ('file1') do (
  set p1=%%a
  set p2=%%b
  set p3=%%c
)

echo value p1: %p1%
echo value p2: %p2%
echo value p3: %p3%

endlocal
pause


This is just a simple solution to this problem. Depending on the output of the data from File1.exe (converted file File1.cmd) is also the input of data in File2.cmd adapt.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: running an exe on batch...

#3 Post by foxidrive » 08 Oct 2015 04:58

TheHunterManX wrote:I put all my data in the Cred.bat file, then converted it to an exe.

I also do not want a temp file as it can be accessed if someone clicks it as it is being ran.



Compiled batch files work by creating the actual temporary batch script on the hard drive to run it.
and it can be accessed by anyone with the knowledge to locate it.

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#4 Post by TheHunterManX » 08 Oct 2015 06:57

Thanks trebor68for posting a solution! I will test it out in a bit...

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#5 Post by TheHunterManX » 09 Oct 2015 05:09

Sorry, but it didnt work,when i have the files alone they work(File1.cmd
File2.cmd), but when I compile the .cmd into a .exe, delete File1.cmd, and run File2.cmd, it doesnt work(File1.exe, File2.cmd). Please try another solution :D

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: running an exe on batch...

#6 Post by penpen » 10 Oct 2015 03:12

Could it be, that you are using an option "invisible" (or similar) when you are "compiling" the batch to an executable using something like http://www.f2ko.de/en/ob2e.php?

If it is true notice that in such a case the file1.exe process opens an own hidden console window to execute the local copy of file1.cmd, including:
- host for console window
- windows command processor
- file1.exe
(You may use the task manager to see these processes/tasks.)

If they include any user input they might run forever, so you have to close the exe and the (hidden) windows command processor manually (in this order) - the host closes automatically.

(So better avoid such options.)

If you need to use this option, you probably have to use temporary files, for example:
- redirect the output of the echo in "file1.cmd" to "p123.txt"
- change the data source of "for /f" to the tmporary file
- delete the temporary file


penpen

Edit: Section 2: Corrected a faulty description by replacing:
"that the file1.exe process is opened in its own hidden console window" with
"that in such a case the file1.exe process opens an own hidden console window to execute the local copy of file1.cmd".
Last edited by penpen on 10 Oct 2015 10:19, edited 1 time in total.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: running an exe on batch...

#7 Post by Aacini » 10 Oct 2015 08:02

When an .exe file is executed, the system creates a new local copy of the environment for it, so any change made in this environment is lost when the .exe ends. There is no way to return a value from an .exe program to its parent cmd.exe environment, don't matters if the .exe was created compiling a source .bat file.

I am pretty sure that previous trebor68's solution should work. Create this File1.bat:

Code: Select all

@echo off
echo 1 2 7

Compile it and execute this command:

Code: Select all

File1.exe > output.txt

After that, the output.txt file should contain this line:

Code: Select all

1 2 7

If not, then the problem is related to the compiler itself. If the text file does contain previous line, then trebor68's solution should work.

We need more details on the problem, because "it doesnt work" don't helps...

Antonio

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#8 Post by TheHunterManX » 10 Oct 2015 12:38

So since i cannot just say it doesnt work, I will upload a video shortly...

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: running an exe on batch...

#9 Post by Squashman » 10 Oct 2015 12:43

TheHunterManX wrote:So since i cannot just say it doesnt work, I will upload a video shortly...

Not really necessary.
What you could do is provide a lot more detail. Like what bat to exe compiler you are using. What Windows Operating System you are using. The EXACT code you are using(NO OBFUSCATED CODE)!

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: running an exe on batch...

#10 Post by trebor68 » 10 Oct 2015 13:40

Try again my first file without the commands "SETLOCAL" and "ENDLOCAL". See also the message from Aacini.

The output of the three values in file File1.cmd carried out in a single line. The reading is also of three individual values, each consisting of a single value with no spaces or commas.

Before you work with complex values want to try once to test with simple values.

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#11 Post by TheHunterManX » 10 Oct 2015 13:53

I know to work with simple first for testing...
So the file1.cmd and file2.cmd worked, however, when i compiled file1.cmd and executed file2.cmd again it did not give values. I have turned off setlocal and used it.
Operating system (it does not matter however i will still reveal it):
Windows xp sp3
Compiling:
Bat2exe.exe (offline program)

Other info: When i run file1.exe alone it runs cmd saying the numbers but it doesnt when i run file2.cmd. This does work if file1.cmd in not compiled.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: running an exe on batch...

#12 Post by Squashman » 10 Oct 2015 13:59

TheHunterManX wrote:Bat2exe.exe (offline program)

What website did you get it from?
What parameters did you compile it with?

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#13 Post by TheHunterManX » 10 Oct 2015 14:05

this one: http://www.f2ko.de/en/b2e.php
but i use 1.4 instead because it is easier.
Also there is only input file, icon, paste, and output file.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: running an exe on batch...

#14 Post by Aacini » 10 Oct 2015 14:43

TheHunterManX wrote:
Other info: When i run file1.exe alone it runs cmd saying the numbers but it doesnt when i run file2.cmd. This does work if file1.cmd in not compiled.

How do you know that file1.exe "runs cmd"? If you run file1.exe alone the output must be just one line with the three numbers only: "1 2 7".

Please, do the following: execute this line

Code: Select all

file1.exe > output.txt

Then, post here the contents of output.txt file. Please, use code tags to enclose the file contents: enter left square-braquet, "code" without the quotes and right square-braquet in a line; then the contents of the file and after it: left square-braquet, "/code" without the quotes, and right square-braquet.

Antonio

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: running an exe on batch...

#15 Post by TheHunterManX » 10 Oct 2015 14:48

So here is the output...
[code][/code]
Nothing! when i run the file1.exe it runs cmd(command prompt to be exact) and closes a half second later and i see the numbers for a split second.

Post Reply