Hot Topic (More than 10 Replies) Running a cmd line from @shell (Read 1811 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Running a cmd line from @shell
Mar 24th, 2012 at 5:51pm
Print Post Print Post  
When I type this line below on a command line it works perfect.

pdftk c:\sb2\in1.pdf c:\sb2in2.pdf cat output c:\attach\out9.pdf

But I cannot seem to get it to work from Sbasic with @shell.  I have tried what seems to be hundreds of different ways with no success. Below are a few. What do I have incorrect?

m = @Shell( "pdftk" + @Chr(34) + "c:\sb2\in1.pdf" + @Chr(34) + " " + @Chr(34) + "c:\sb2\in2.pdf" + @Chr(34) + " " + @Chr(34) + "cat" + @Chr(34) + " " + @Chr(34) + "output" + @Chr(34) + " " + @Chr(34) + "out6.pdf" + @Chr(34))

m = @Shell( "pdftk " +" " + @Chr(34) + "c:\sb2\in1.pdf" + @Chr(34) + " " + @Chr(34) + "c:\sb2\in2.pdf" + @Chr(34) + " " + @Chr(34) + "cat" + @Chr(34) + " " + @Chr(34) + "output" + @Chr(34) + " " + @Chr(34) + "c:\attach\out6.pdf" + @Chr(34))

m = @Shell( @Chr(34) + "pdftk" + @Chr(34)  + " " + @Chr(34)+ "c:\sb2\in1.pdf" + @Chr(34) + " " + @Chr(34) + " " + "c:\sb2\in2.pdf" + @Chr(34) + " " + @Chr(34) + "cat" + @Chr(34) + " " + @Chr(34) + "output" + @Chr(34) + " " + @Chr(34) + "c:\attach\out9.pdf" + @Chr(34))

m = @Shell( "pdftk c:\sb2\in1.pdf  c:\sb2\in2.pdf  cat output c:\attach\out9.pdf" )

m = @Shell( "pdftk " + @Chr(34) + "c:\sb2\in1.pdf " + @Chr(34) + "c:\sb2\in2.pdf " + @Chr(34) + "cat " + @Chr(34)  + "output " + @Chr(34) +  "c:\attach\out9.pdf" + @Chr(34))

Thanks!
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Running a cmd line from @shell
Reply #1 - Mar 24th, 2012 at 9:02pm
Print Post Print Post  
Have you tried sending these strings to Writeln, then cut & pasting them to an actual command line, to see if they produce any sort of errors?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Running a cmd line from @shell
Reply #2 - Mar 24th, 2012 at 9:03pm
Print Post Print Post  
Bob,

This works for me:

vConvertHTMLtoImage = "converthtmltoimage.exe /file" + " " + @chr(34) + "w:\sesame2\invoices\" + vInvoiceHTML + @chr(34) + " /dir " + @chr(34) + "w:\sesame2\invoices" + @chr(34) + " /name " + @chr(34) + "WordComInvoice" + vSONum + @chr(34) + " /quality " + "80"
                                                                       

FileOverWrite("w:\sesame2\convert.bat", "c:" + @NewLine() + "cd\" + @NewLine() + "cd" + " " + @chr(34) + "program files" + @chr(34) + @NewLine() + "cd" + " " + @chr(34) + "convert html to image" + @chr(34) + @NewLine() + vConvertHTMLtoImage)


Like you, I could get it the first section to work fine when I was on the command line, but could not get it to work via @Shell.  So I wrote the second line to create a batch file (which just navigates back to the root directory and the changes directories till I get to the directory from which I run the command line code) and then run the batch file, using the variable I had built for the command line.  It works great inside the batch file.
  

Larry
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Running a cmd line from @shell
Reply #3 - Mar 24th, 2012 at 11:15pm
Print Post Print Post  
Could it be that the command is not in the path, and you need to specify the full pathname for the "pdftk" exe file?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Running a cmd line from @shell
Reply #4 - Mar 24th, 2012 at 11:27pm
Print Post Print Post  
Also, as Mark pointed out...
If you send those lines to the slate, you end up with these results:
Code
Select All
pdftk"c:\sb2\in1.pdf" "c:\sb2\in2.pdf" "cat" "output" "out6.pdf"
pdftk  "c:\sb2\in1.pdf" "c:\sb2\in2.pdf" "cat" "output" "c:\attach\out6.pdf"
"pdftk" "c:\sb2\in1.pdf" " c:\sb2\in2.pdf" "cat" "output" "c:\attach\out9.pdf"
pdftk c:\sb2\in1.pdf  c:\sb2\in2.pdf  cat output c:\attach\out9.pdf
pdftk "c:\sb2\in1.pdf "c:\sb2\in2.pdf "cat "output "c:\attach\out9.pdf"
 



Not one of those match the line you say works perfectly (which also has a typo in it -- it's missing a backslash before "in2.pdf"). One comes close, but has extra spaces. I'm not sure if that would mess it up, or not.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Running a cmd line from @shell
Reply #5 - Mar 25th, 2012 at 12:34am
Print Post Print Post  
Hi Robert,
Not much has left to be contributed when Mark, Carl and Larry have weighed in!! The only thing I am thinking is:
The path for pdftk program is not in Environment variable.
cat and output should never be under bracket.
pdfkt should not have bracket.
No need to enclose any part of command in bracket unless there is space in that part of the command. Even if you enclose the file with path in brackets, that should be fine.
Where exactly did you put the commandline command on shell manually? Is it just anywhere or in the proper path of pdftk program file.
Putting WriteLn windows for catching exactly what goes in with @Shell ( ) command is the key to debugging the code.
I have been using pdfill program that does the same thing including filling out forms and it has similar commandline. Works Perfectly. However, I do not think for a second that anything wrong with pdftk.
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Running a cmd line from @shell
Reply #6 - Mar 25th, 2012 at 5:22am
Print Post Print Post  
Thanks everyone  for all the ideas.

over the past few days I have tried everything that was mentioned and after reading your suggestions today I started over from scratch and tried everything again.

I can write out to the slate and copy the txt and paste it into the command line at any propmpt (c:\ or c:\sesame etc) and it runs perfect.


I also added the full path of pdftk and still no good with @shell.

The line below is from slate window and runs perfectly when pasted onto the command line.

Is there any reason @shell would not pass the txt the exact same way?

I will try Pdfill since Bharat has had success using it.

Thanks you so much to you all!

c:\windows\system32\pdftk c:\sb2\in1.pdf  c:\sb2\in2.pdf  cat output c:\attach\out7.pdf
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Running a cmd line from @shell
Reply #7 - Mar 25th, 2012 at 12:35pm
Print Post Print Post  
If you suspect @Shell() may have a problem with it, maybe you should try it with CreateAProcess(). I'm not positive, but I do seem to remember that in my experience, certain things would only work with CreatAProcess.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Running a cmd line from @shell
Reply #8 - Mar 25th, 2012 at 1:18pm
Print Post Print Post  
I chose @Shell in this particular type situ because it's synchronous (waits for the executable invoked to run before Sesame continues on), whereas CreateAProcess is asynchonous (Sesame doesn't wait for CreateAProcess's executable to finish before Sesame continues on)
  

Larry
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Running a cmd line from @shell
Reply #9 - Mar 25th, 2012 at 1:18pm
Print Post Print Post  
Does the Shell open up? what error you are getting? Could it be that Shell is not opening up? In that case you need to put cmd /C before the command. Normally @Shell ( ) command does not need cmd /c switch but since you have tried everything else, would not hurt to try this one also. Just a thought. 

  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Running a cmd line from @shell
Reply #10 - Mar 25th, 2012 at 6:15pm
Print Post Print Post  
Well another one of the many mysteries of life to me. PDFTK does not work with @shell or createaprocess or anything else I try, However using PDFPG or many of the other PDF choices it works exactly as I tried using it on Wednesday.

I am going to look on the bright side and realize I could have kept chasing my tail for another couple of weeks if it wasn't for you all. Probably the last thing I would have thought to change on my own would have been the program I was trying to run.

So thanks everyone for all the help. Its great knowing your all out there, I couldn't imagine getting through this stuff without all of you!
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Running a cmd line from @shell
Reply #11 - Mar 25th, 2012 at 7:28pm
Print Post Print Post  
Following is the info about PDFill. I have been using it for the past couple of years and it has been working flawlessly.

http://www.pdfill.com/pdf_batch_command.html
http://www.pdfill.com/pdf_form_filler.html

The real strength of of PdFill is in filling out pdf form using data from Sesame on the fly.

Since you are working with making and merging pdf files, also check DocuCom PDF Driver by Zeon corporation that can either append or name sequentially as required in the designated folder.

Unfortunately, one program cannot do everything. I had to use more than one pdf utilities to accomplish creating complete medical record including all attached documents  in pdf with a click of a button. And quite frequently the resultant pdf file has more than 100 pages!
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Running a cmd line from @shell
Reply #12 - Mar 26th, 2012 at 12:02am
Print Post Print Post  
lksseven wrote on Mar 25th, 2012 at 1:18pm:
I chose @Shell in this particular type situ because it's synchronous (waits for the executable invoked to run before Sesame continues on), whereas CreateAProcess is asynchonous (Sesame doesn't wait for CreateAProcess's executable to finish before Sesame continues on)

Not that it can be used here (because Bob has already posted that PDFTK wouldn't work in CreateAProcess), but @RedirectProcess is more like CreateAProcess, yet is a synchronous command that will make Sesame wait until it's done. Just an FYI that may help someone else.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged