Lossadil
Posts: 15
Joined: Fri Jul 09, 2010 12:11 pm

Postby Lossadil » Wed Nov 30, 2011 3:45 pm

Hi,

It's certainly not a bug but I will become crazy ... I really do not understand how this "Post Processing Open Command" works ...

When I launch manually a simple batch (start.bat) in the same folder as my report.txt (from awasu), it works perfectly.

But when I try to launch it automatically with "Post Processing...", it partialy works ... (the purpose of the batch file is to create 7 files, and it only create ones)

What do I need to put in the field ?

As explained here : "cmd /c start" with the right selection of "run in directory" doesn't work ...

Here te content of my batch file :

Code: Select all

@echo off
sed "s/^xyx614xyx\(.\{50\}\).*xyx624xyx/xyx614xyx\1xyx624xyx/" < file_1.txt > file_2.txt
sed "s/xyx624xyx\(.\{20\}\).*xyx634xyx/xyx624xyx\1xyx634xyx/" < file_2.txt > file_3.txt
sed "s/xyx634xyx\(.\{10\}\).*xyx634xyx/xyx624xyx\1xyx644xyx/" < file_3.txt > file_4.txt

sed  "$ s/xyx694xyx//g" < file_4.txt > file_5.txt

sed -f replace2.sed < file_5.txt > file_6.txt

iconv.exe -c -f UTF-8 -t UTF-16  file_6.txt > file_7.txt

sqlcmd -S SQL1\SQL1 -i E:\Awasu\insert.sql


In this case, it only do the work for the first line (< file_1.txt > file_2.txt)

No comment on the content of this script, thanks ;-)

User avatar
support
Site Admin
Posts: 3021
Joined: Fri Feb 07, 2003 12:48 pm
Location: Melbourne, Australia
Contact:

Postby support » Wed Nov 30, 2011 6:54 pm

Generally speaking, "Run in directory" should work but off the top of my head (it's 2am here and I've just got home :-() I think CMD.EXE might be a special case and may not honor the working directory set by the calling process - it will probably try to start in %HOME or something like that :|

Try putting a CD at the start of your batch file and see if that makes a difference...

User avatar
kevotheclone
Posts: 239
Joined: Mon Sep 08, 2008 7:16 pm
Location: Elk Grove, California

Postby kevotheclone » Thu Dec 01, 2011 9:05 am

IIRC we had some issue(s) with running a batch file as a "post-processing command", but I think it had to do with passing parameters into the batch file. I know I have the conversation archived, so I may be able to dig it up and summarize it here. From my memory, I think we never resolved the problem and decided that in certain situations the user should write a simple JScript/Perl/Python/Ruby/VBScript script that executes the commands using the passed parameters.

Back to the current "Run in directory" issue...

A simple test

In the simplest scenario I could devise, running a batch file with a specified "Run in directory" value seems to work correctly for me.
Create a helloworld.bat file that contains the following lines:

Code: Select all

@echo off
echo hello world > helloworld.txt

Note: In these tests I did not use "cmd /c" or "cmd /c start".

Running this batch file as a "post-processing command" without specifying a "Run in directory" creates the helloworld.txt file in the same directory as Awasu.exe.
Running this batch file as a "post-processing command" specifying a "Run in directory" creates the helloworld.txt file in the directory specified by the "Run in directory" field.

One step up the evolutionary chain

My tests with a multiple command batch file like yours yielded the same results; only the first command seemed to execute. So I experimented by placing each command on the same line separated by the "command separator" (&&) and it seems to work. I know this "ain't purdy" as we say in "the states", but it looks like it'll work.

Note: I had a problems running your exact script. I don't have iconv.exe and I'm not a sed.exe expert so I made a simple Windows batch file that looks for lines containing "html" in the input file and echos them on to the output file.

Code: Select all

@echo off

REM Ignore the line wrapping this is really all on one line:
findstr "html" < file_1.txt > file_2.txt && findstr "html" < file_2.txt > file_3.txt && findstr "html" < file_3.txt > file_4.txt && findstr "html" < file_4.txt > file_5.txt && findstr "html" < file_5.txt > file_6.txt

When run as a "post-processing command" with a specified a "Run in directory" all 6 files are created. File_1.txt contains the full Channel Report text while files 2-6 contain only the lines that contain the "html" substring.

Even though this seems to work I still receive an error message when I check the return code: The external command failed: return code 255

Prefixing the "post-processing command" with "cmd /c" yields the same results as above while prefixing with "cmd /k" yields: The external command failed: return code 1

Maybe one of the lines is returning an error code and somehow CreateProcess() grabs it and exits, and maybe by making it a one-liner the error code doesn't get returned until the whole line executes

Finally, regarding the previous suggestion of putting a CD at the start of your batch file, many people don't know that, within batch files only, there is an environment variable named %CD% that contains current directory. Don't bother looking for it at the command prompt using the SET command, you won't find it, but you can echo %CD% > test_file.txt to see that %CD% exists. So maybe you could prefix your file names with either .\file_1.txt or %CD%\file_1.txt.

Lossadil
Posts: 15
Joined: Fri Jul 09, 2010 12:11 pm

Postby Lossadil » Thu Dec 01, 2011 10:11 am

Apparently, "sed.exe" is at the root of the issue ... The process always stops after the first "sed.exe" command.

Code: Select all

@echo off

cd e:\

echo >> test_a.txt
echo >> test_b.txt

iconv.exe -c -f UTF-8 -t UTF-16  test_1.txt > test_7.txt
iconv.exe -c -f UTF-8 -t UTF-16  test_7.txt > test_8.txt

echo >> test_c.txt

sed.exe -f replace2.sed < test_8.txt > test_9.txt

echo >> test_d.txt
echo >> test_e.txt

sqlcmd -S SQL1\SQL1 -i E:\insert.sql

pause


Run perfectly manually but automatically, it never create the "test_d.txt" ...

I've tried with "cd" but doesn't work ...

Lossadil
Posts: 15
Joined: Fri Jul 09, 2010 12:11 pm

Postby Lossadil » Thu Dec 01, 2011 11:13 am

Sorry ... we've answered on the same time. I've tried some of your proposition but apparently, they didn't work ...

and ... I finally found a solution ... As you said, use other script language ... But I'm so confortable with my sed.exe command ;-)))

So, I run my start.bat with vb and that works perfectly with this command line "wscript.exe start.vbs"

... and this start.vbs:

Code: Select all

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K start.bat"), 1, True


Thanks !!!

Still some few tests before professional version purchase ;-)))

User avatar
support
Site Admin
Posts: 3021
Joined: Fri Feb 07, 2003 12:48 pm
Location: Melbourne, Australia
Contact:

Postby support » Thu Dec 01, 2011 6:44 pm

Lossadil wrote:Apparently, "sed.exe" is at the root of the issue ... The process always stops after the first "sed.exe" command.

Are you sure the process is stopping? If the test_d.txt file is not being created, my first guess would be is that the sed process is not exiting. If there's a working directory problem, it might be looking for the input file (test_8.txt), not finding it, and then does something like switching to stdin and hanging waiting for input. Or maybe it is creating the test_d.txt, just not where you're looking for it...?

Lossadil
Posts: 15
Joined: Fri Jul 09, 2010 12:11 pm

Postby Lossadil » Sat Dec 03, 2011 11:48 am

No, if I run manually the batch or launch it via the vb trick, it works like a charm ... So I guess there is some problem with sed and awasu ...

Like I said, it's not a big deal ...


Return to “Awasu - Bug Reports”

Who is online

Users browsing this forum: No registered users and 6 guests