Problems with script which call another file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
rabantot
Posts: 5
Joined: 02 Sep 2009 17:35

Problems with script which call another file

#1 Post by rabantot » 13 Apr 2010 15:36

Hello,

I would appreciate you guys could help me with this little problem.
I have a application called WinSCP in order to download some files to one LAN server from another server (located in my DMZ).
In order to automate the download process I created two files:
The first one is a *.cmd file that calls some connection parameters from the second one (a *.txt file)
They're as follows:

file1.cmd
-------------------------------------------------------------
"C:\Program Files\WinSCP\winscp" /console /script=Conexion.txt
-------------------------------------------------------------

Conexion.txt
-------------------------------------------------------------
open sftp://User1:Password@192.168.1.10:22 -privatekey=pelim.ppk
option transfer ascii
cd /home
synchronize local "C:\Program Files\WinSCP\Files" /home
close
exit
-------------------------------------------------------------

Whenever I executed the file1.cmd manually, it works normally. But when I try to execute it from a scheduled task, it doesn't work and I can see the scheduled task to be running for the eternity.

How can I do in order to make ir works fime from the schedule task?

Regards,
Rabantot

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Problems with script which call another file

#2 Post by !k » 13 Apr 2010 15:59

Try to specify the full path to Conexion.txt
"C:\Program Files\WinSCP\winscp" /console /script="c:\path to\Conexion.txt"

rabantot
Posts: 5
Joined: 02 Sep 2009 17:35

Re: Problems with script which call another file

#3 Post by rabantot » 14 Apr 2010 12:02

I just tried putting the complete path to the Conexion.txt file and the results are the same. Or Could you please suggest me another way to put the files together and manages to use the WinSCP commands without incompatibility problems???

Thank you very much
Regards,
Rabantot

!k wrote:Try to specify the full path to Conexion.txt
"C:\Program Files\WinSCP\winscp" /console /script="c:\path to\Conexion.txt"

crr
Posts: 2
Joined: 18 May 2011 09:58

Re: Problems with script which call another file

#4 Post by crr » 18 May 2011 10:02

Hi Rabantot,

I am having the same problem you have, exatly the same
have you by any chance found the solution?
any body can help us here?

If not, is there any comand line software to SCP files from a windows server to other boxes?

thanks in advance for your replies

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#5 Post by Ed Dyreen » 18 May 2011 11:02

DO_AT.CMD

Code: Select all

   set "FullPath.SOURCE=!FullPath.PRGM3TH!\SYS\CFG\SchTasks"

   set "?=1sthMonth.CMD"    &set /p "?=  :/ !?!    "<nul
   ::(
      at 00:00 /interactive /every:1 "!FullPath.SOURCE!\!?!"
   ::)

   set "?=Saturday.CMD"    &set /p "?=  :/ !?!    "<nul
   ::(
      at 00:00 /interactive /every:za "!FullPath.SOURCE!\!?!"
   ::)


1sthMonth.CMD

Code: Select all

set "FullPath=!Drive.PRGM3TH!\SYS\CFG\SchTasks\1sthMonth"
::
Pushd "!FullPath!\" &&(
   ::
   for /f "tokens=*" %%! in (

      '2^>nul dir /a:-d /b "*.CMD"'

   ) do (
      set "File=%%!"
      set "FullPathFile=!FullPath!\!File!"
      ::
      echo. &set /p "?=  :/ !File!..." <nul
      ::^(
         start "!File!" /low /wait "!FullPathFile!"
      ::
      set /p "?= [OK]" <nul &echo.
      ::^)
      echo.>nul
   )
::
popd
)


This works for me.

crr
Posts: 2
Joined: 18 May 2011 09:58

Re: Problems with script which call another file

#6 Post by crr » 19 May 2011 01:55

I think that scripts are not the answer to our question, right?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#7 Post by Ed Dyreen » 19 May 2011 06:04

Then I don't understand the question, I thought a method was needed to schedule a task that wouldn't hang when launched by the scheduler.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#8 Post by Ed Dyreen » 19 May 2011 06:50

You are not the only one, i've had the same problem I believe. In my case it had to do with who launched the process. But I don't really remember so I stop here :roll:

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Problems with script which call another file

#9 Post by alan_b » 19 May 2011 12:42

Ed Dyreen wrote:
1sthMonth.CMD

Code: Select all

   ) do (
      set "File=%%!"
      set "FullPathFile=!FullPath!\!File!"
      ::
      echo. &set /p "?=  :/ !File!..." <nul
      ::^(
         start "!File!" /low /wait "!FullPathFile!"
      ::
      set /p "?= [OK]" <nul &echo.
      ::^)
      echo.>nul
   )


This works for me.


Are you sure ?
I always expect grief from a label within parenthesis,
so I would expect surprises are imminent with 4 sets of double colon :: .

Regards
Alan

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#10 Post by Ed Dyreen » 19 May 2011 13:13

I am not going to discuss the syntax, people asking me wy do you put this in parenthesis or that it isn't necesarry..., it's only a piece of the code.
I am not going to solve a problem it is meant as a hint nomore than that.
I was just wondering how @rabantot scheduled these tasks.

@alan_b
I always expect grief from a label within parenthesis,

It's ripped out of a WORKING script.

There is nothing wrong with

(
::
echo.>nul
::^(
echo.>nul
::
echo.dude why this weird syntax.
)

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Problems with script which call another file

#11 Post by jeb » 19 May 2011 14:10

alan_b wrote:Are you sure ?
I always expect grief from a label within parenthesis,


Ed Dyreen wrote:It's ripped out of a WORKING script.


You are right, both.

: and :: are allowed in parenthesis, but not at any line and not in any combination.

Somewhere I have posted a complete explanation at lingubender rem vs ::

jeb

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Problems with script which call another file

#12 Post by alan_b » 20 May 2011 10:56

Thanks, I have learnt something new today.

Please explain the purpose of these ::
Are they simply a complicated way of inserting almost blank "white space" between lines of CMD code without breaking the code,
or do they modify the execution of the code,
and I need to use WinSCP to see the difference with and without the ::

Regards
Alan

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#13 Post by Ed Dyreen » 20 May 2011 11:20

Just a programming style I use

Code: Select all


:Label "( /Str: "String|Byval" /Optional )"
::
:: This does nothing
SetLocal
::(
     ::Open a subject
     ::(
          echo.Hi. My Name is.. ED
     ::)

     ::that's no subject
     ::(
          echo.realy?>nul
     ::)
::
(
     endlocal

     seterror
)
goto :eof ()
::)

:lol: I could also use rem but I like this better

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Problems with script which call another file

#14 Post by alan_b » 20 May 2011 13:12

Nearly 3 decades ago my very first P.C. had the luxury of a 20 MB HDD.
As a result I developed a frugal programming style

Abraham Lincoln advocated my preferred programming style when he said :-
"Better to remain silent and be thought a fool than to speak out and remove all doubt."

I respect your capability,
but for me to use these double colon tricks would be venturing beyond my capabilities,
and I would fall flat on my face.

Regards
Alan

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Problems with script which call another file

#15 Post by Ed Dyreen » 20 May 2011 13:15

@alan_b
I respect your capability,
but for me to use these double colon tricks would be venturing beyond my capabilities,
and I would fall flat on my face.

Is this ironic :(

"Better to remain silent and be thought a fool than to speak out and remove all doubt."

Maybe, well I won't speak to you then :lol:

Post Reply