Task Scheduler truncates PATH variable?!

Discussion in 'Microsoft Windows 2000 CMD Promt' started by Angel Tsankov, Feb 5, 2006.

  1. Hello,

    I have a simple batch file that prints the PATH environment variable:
    @echo off
    echo %PATH%
    pause

    I noticed that when I execute this file from the run menu it displays
    the PATH as expected. If, however, I execute it via the Task Scheduler
    it displays the PATH variable up to some number of characters. It
    seems that the variable has been truncated. How can I fix this?
     
    Angel Tsankov, Feb 5, 2006
    #1
    1. Advertisements

  2. Angel Tsankov

    Rich Pasco Guest

    I ran your program on my system and saw the entire path, both as a
    scheuled task and from the command line. In short, I could not
    reproduce your problem. Running WinXP Pro.

    - Rich

    Angel Tsankov wrote:

    > Hello,
    >
    > I have a simple batch file that prints the PATH environment variable:
    > @echo off
    > echo %PATH%
    > pause
    >
    > I noticed that when I execute this file from the run menu it displays
    > the PATH as expected. If, however, I execute it via the Task Scheduler
    > it displays the PATH variable up to some number of characters. It
    > seems that the variable has been truncated. How can I fix this?
    >
     
    Rich Pasco, Feb 6, 2006
    #2
    1. Advertisements

  3. Angel Tsankov

    Mark V Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:

    > Hello,
    >
    > I have a simple batch file that prints the PATH environment
    > variable: @echo off
    > echo %PATH%
    > pause
    >
    > I noticed that when I execute this file from the run menu it
    > displays the PATH as expected. If, however, I execute it via the
    > Task Scheduler it displays the PATH variable up to some number
    > of characters. It seems that the variable has been truncated.
    > How can I fix this?


    What OS is always a good thing! <G>

    If there is a truncation issue in in TS, I do not know of it.

    Bear in mind the the %PATH% you see displayed will be that of the
    account which is executing your batch. That could be an account
    (and a different PATH content) than your own logged-on account. I
    suspect this is the issue and that you should either specify the
    account (for the task) or simply be aware of the account (and
    variables) your are actually using at the time. This could be
    *very* important since both Authority and environment may be
    different.
     
    Mark V, Feb 6, 2006
    #3
  4. >> Hello,
    >>
    >> I have a simple batch file that prints the PATH environment
    >> variable: @echo off
    >> echo %PATH%
    >> pause
    >>
    >> I noticed that when I execute this file from the run menu it
    >> displays the PATH as expected. If, however, I execute it via the
    >> Task Scheduler it displays the PATH variable up to some number
    >> of characters. It seems that the variable has been truncated.
    >> How can I fix this?

    >
    > What OS is always a good thing! <G>
    >
    > If there is a truncation issue in in TS, I do not know of it.
    >
    > Bear in mind the the %PATH% you see displayed will be that of the
    > account which is executing your batch. That could be an account
    > (and a different PATH content) than your own logged-on account. I
    > suspect this is the issue and that you should either specify the
    > account (for the task) or simply be aware of the account (and
    > variables) your are actually using at the time. This could be
    > *very* important since both Authority and environment may be
    > different.


    The OS is Win XP Pro SP2 with the latest automatic updates applied.
    I run the batch file with the same account in both cases.
    I noticed that the PATH env var is truncated in the middle of a
    folder. The length of PATH is 1510 cahracters.
    Any other ideas?
     
    Angel Tsankov, Feb 6, 2006
    #4
  5. >I ran your program on my system and saw the entire path, both as a
    > scheuled task and from the command line. In short, I could not
    > reproduce your problem. Running WinXP Pro.


    I'm running WinXP Pro, too.
    I noticed that the PATH env var is truncated in the middle of a
    folder. The length of PATH is 1510 cahracters.
    Any other ideas?
     
    Angel Tsankov, Feb 6, 2006
    #5
  6. Angel Tsankov

    Mark V Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:

    >>> Hello,
    >>>
    >>> I have a simple batch file that prints the PATH environment
    >>> variable: @echo off
    >>> echo %PATH%
    >>> pause
    >>>
    >>> I noticed that when I execute this file from the run menu it
    >>> displays the PATH as expected. If, however, I execute it via

    the
    >>> Task Scheduler it displays the PATH variable up to some number
    >>> of characters. It seems that the variable has been truncated.
    >>> How can I fix this?

    >>
    >> What OS is always a good thing! <G>
    >>
    >> If there is a truncation issue in in TS, I do not know of it.
    >>
    >> Bear in mind the the %PATH% you see displayed will be that of

    the
    >> account which is executing your batch. That could be an account
    >> (and a different PATH content) than your own logged-on account.

    I
    >> suspect this is the issue and that you should either specify the
    >> account (for the task) or simply be aware of the account (and
    >> variables) your are actually using at the time. This could be
    >> *very* important since both Authority and environment may be
    >> different.

    >
    > The OS is Win XP Pro SP2 with the latest automatic updates

    applied.
    > I run the batch file with the same account in both cases.
    > I noticed that the PATH env var is truncated in the middle of a
    > folder. The length of PATH is 1510 cahracters.
    > Any other ideas?


    None. Sorry, I use neither XP nor the Task Scheduler (W2K here).
    That is certainly odd. Perhaps your very-long-PATH can and should
    be shortened considerably? Not that this is an explanation of
    course. Did you try echo/redirect %PATH% to a file?
     
    Mark V, Feb 6, 2006
    #6
  7. >>>> Hello,
    >>>>
    >>>> I have a simple batch file that prints the PATH environment
    >>>> variable: @echo off
    >>>> echo %PATH%
    >>>> pause
    >>>>
    >>>> I noticed that when I execute this file from the run menu it
    >>>> displays the PATH as expected. If, however, I execute it via

    > the
    >>>> Task Scheduler it displays the PATH variable up to some number
    >>>> of characters. It seems that the variable has been truncated.
    >>>> How can I fix this?
    >>>
    >>> What OS is always a good thing! <G>
    >>>
    >>> If there is a truncation issue in in TS, I do not know of it.
    >>>
    >>> Bear in mind the the %PATH% you see displayed will be that of

    > the
    >>> account which is executing your batch. That could be an account
    >>> (and a different PATH content) than your own logged-on account.

    > I
    >>> suspect this is the issue and that you should either specify the
    >>> account (for the task) or simply be aware of the account (and
    >>> variables) your are actually using at the time. This could be
    >>> *very* important since both Authority and environment may be
    >>> different.

    >>
    >> The OS is Win XP Pro SP2 with the latest automatic updates

    > applied.
    >> I run the batch file with the same account in both cases.
    >> I noticed that the PATH env var is truncated in the middle of a
    >> folder. The length of PATH is 1510 cahracters.
    >> Any other ideas?

    >
    > None. Sorry, I use neither XP nor the Task Scheduler (W2K here).
    > That is certainly odd. Perhaps your very-long-PATH can and should
    > be shortened considerably? Not that this is an explanation of
    > course. Did you try echo/redirect %PATH% to a file?


    Same result - only the first 1024 characters are echoed.
    Besides, I cannot shorten my PATH as I access my programs via the run
    menu, from the command prompt and batch files. Putting the respective
    paths in the PATH variable seems to suits these needs very well.
     
    Angel Tsankov, Feb 6, 2006
    #7
  8. Angel Tsankov

    Gary Smith Guest

    Perhaps the task scheduler itself has a limit. Do you know whether it's
    actually truncating the path, or is it just truncating the display? You
    could use this command in place of the echo in your batch file to make it
    clearer:

    for %%A in ("%path:;=" "%") do @echo %%~A


    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov <-sofia.bg> wrote:
    > I have a simple batch file that prints the PATH environment variable:
    > @echo off
    > echo %PATH%
    > pause


    > I noticed that when I execute this file from the run menu it displays
    > the PATH as expected. If, however, I execute it via the Task Scheduler
    > it displays the PATH variable up to some number of characters. It
    > seems that the variable has been truncated. How can I fix this?


    --
    Gary L. Smith
    Columbus, Ohio
     
    Gary Smith, Feb 6, 2006
    #8
  9. Angel Tsankov

    Rich Pasco Guest

    Angel Tsankov wrote:

    >>I ran your program on my system and saw the entire path, both as a
    >> scheuled task and from the command line. In short, I could not
    >> reproduce your problem. Running WinXP Pro.

    >
    > I'm running WinXP Pro, too.
    > I noticed that the PATH env var is truncated in the middle of a
    > folder. The length of PATH is 1510 cahracters.
    > Any other ideas?


    My PATH is only 776 characters, which might explain why mine isn't
    getting truncated. To what length was yours truncated?

    - Rich\
     
    Rich Pasco, Feb 7, 2006
    #9
  10. "Rich Pasco" <> wrote in message
    news:...
    > Angel Tsankov wrote:
    >
    >>>I ran your program on my system and saw the entire path, both as a
    >>> scheuled task and from the command line. In short, I could not
    >>> reproduce your problem. Running WinXP Pro.

    >>
    >> I'm running WinXP Pro, too.
    >> I noticed that the PATH env var is truncated in the middle of a
    >> folder. The length of PATH is 1510 cahracters.
    >> Any other ideas?

    >
    > My PATH is only 776 characters, which might explain why mine isn't
    > getting truncated. To what length was yours truncated?


    To 1024 characters. For more info, take a look at one of the other
    subthreads in this thread.
     
    Angel Tsankov, Feb 7, 2006
    #10
  11. "Gary Smith" <> wrote in message
    news:...
    > Perhaps the task scheduler itself has a limit. Do you know whether
    > it's
    > actually truncating the path, or is it just truncating the display?
    > You
    > could use this command in place of the echo in your batch file to
    > make it
    > clearer:
    >
    > for %%A in ("%path:;=" "%") do @echo %%~A


    Well, the last path in PATH that is displayed is truncated as before.
     
    Angel Tsankov, Feb 7, 2006
    #11
  12. Angel Tsankov

    Gary Smith Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov <-sofia.bg> wrote:

    > "Gary Smith" <> wrote in message
    > news:...
    > > Perhaps the task scheduler itself has a limit. Do you know whether
    > > it's
    > > actually truncating the path, or is it just truncating the display?
    > > You
    > > could use this command in place of the echo in your batch file to
    > > make it
    > > clearer:
    > >
    > > for %%A in ("%path:;=" "%") do @echo %%~A


    > Well, the last path in PATH that is displayed is truncated as before.


    It sounds like the task scheduler has a built-in limit then. To work
    around this, perhaps you could set the path yourseld in the batch file,
    including only those folders needed for the particular task. The change
    will be undone when the batch file exits.

    --
    Gary L. Smith
    Columbus, Ohio
     
    Gary Smith, Feb 8, 2006
    #12
  13. "Gary Smith" <> wrote in message
    news:%...
    > In microsoft.public.win2000.cmdprompt.admin Angel Tsankov
    > <-sofia.bg> wrote:
    >
    >> "Gary Smith" <> wrote in message
    >> news:...
    >> > Perhaps the task scheduler itself has a limit. Do you know
    >> > whether
    >> > it's
    >> > actually truncating the path, or is it just truncating the
    >> > display?
    >> > You
    >> > could use this command in place of the echo in your batch file to
    >> > make it
    >> > clearer:
    >> >
    >> > for %%A in ("%path:;=" "%") do @echo %%~A

    >
    >> Well, the last path in PATH that is displayed is truncated as
    >> before.

    >
    > It sounds like the task scheduler has a built-in limit then. To
    > work
    > around this, perhaps you could set the path yourseld in the batch
    > file,
    > including only those folders needed for the particular task. The
    > change
    > will be undone when the batch file exits.


    Thanks for your suggestion! I'll have it in mind.
     
    Angel Tsankov, Feb 8, 2006
    #13
  14. >>> > Perhaps the task scheduler itself has a limit. Do you know
    >>> > whether
    >>> > it's
    >>> > actually truncating the path, or is it just truncating the
    >>> > display?
    >>> > You
    >>> > could use this command in place of the echo in your batch file
    >>> > to
    >>> > make it
    >>> > clearer:
    >>> >
    >>> > for %%A in ("%path:;=" "%") do @echo %%~A

    >>
    >>> Well, the last path in PATH that is displayed is truncated as
    >>> before.

    >>
    >> It sounds like the task scheduler has a built-in limit then. To
    >> work


    Well, how can the TS set a limit on the length of env vars? Does it
    copy the env vars when it creates the task or does it rely on the env
    inheritance in child processes.
    In the latter case there should be no problem with the length of PATH,
    right?
     
    Angel Tsankov, Feb 9, 2006
    #14
  15. Angel Tsankov

    Mark V Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:

    >>>>> Hello,
    >>>>>
    >>>>> I have a simple batch file that prints the PATH environment
    >>>>> variable: @echo off
    >>>>> echo %PATH%
    >>>>> pause
    >>>>>
    >>>>> I noticed that when I execute this file from the run menu it
    >>>>> displays the PATH as expected. If, however, I execute it via
    >>>>> Task Scheduler it displays the PATH variable up to some
    >>>>> number of characters. It seems that the variable has been
    >>>>> truncated. How can I fix this?
    >>>>
    >>>> What OS is always a good thing! <G>
    >>>>
    >>>> If there is a truncation issue in in TS, I do not know of it.
    >>>>
    >>>> Bear in mind the the %PATH% you see displayed will be that of
    >>>> the account which is executing your batch. That could be an

    [ ]

    >>> The OS is Win XP Pro SP2 with the latest automatic updates

    >> applied.
    >>> I run the batch file with the same account in both cases.
    >>> I noticed that the PATH env var is truncated in the middle of
    >>> a folder. The length of PATH is 1510 cahracters.
    >>> Any other ideas?


    >> None. Sorry, I use neither XP nor the Task Scheduler (W2K
    >> here). That is certainly odd. Perhaps your very-long-PATH can
    >> and should be shortened considerably? Not that this is an

    [ ]

    > Same result - only the first 1024 characters are echoed.
    > Besides, I cannot shorten my PATH as I access my programs via
    > the run menu, from the command prompt and batch files. Putting
    > the respective paths in the PATH variable seems to suits these
    > needs very well.


    Skiping everything else, how wedded are you to Windows Task
    Scheduler? I don't use it at all and for several reasons.
    Instead, I use nnCron Lite (free and a CKI Win32 clone of cron).
    It you are insterested, I can test for any truncation with over-
    long PATH values.
     
    Mark V, Feb 9, 2006
    #15
  16. "Mark V" <> wrote in message
    news:...
    > In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:
    >
    >>>>>> Hello,
    >>>>>>
    >>>>>> I have a simple batch file that prints the PATH environment
    >>>>>> variable: @echo off
    >>>>>> echo %PATH%
    >>>>>> pause
    >>>>>>
    >>>>>> I noticed that when I execute this file from the run menu it
    >>>>>> displays the PATH as expected. If, however, I execute it via
    >>>>>> Task Scheduler it displays the PATH variable up to some
    >>>>>> number of characters. It seems that the variable has been
    >>>>>> truncated. How can I fix this?
    >>>>>
    >>>>> What OS is always a good thing! <G>
    >>>>>
    >>>>> If there is a truncation issue in in TS, I do not know of it.
    >>>>>
    >>>>> Bear in mind the the %PATH% you see displayed will be that of
    >>>>> the account which is executing your batch. That could be an

    > [ ]
    >
    >>>> The OS is Win XP Pro SP2 with the latest automatic updates
    >>> applied.
    >>>> I run the batch file with the same account in both cases.
    >>>> I noticed that the PATH env var is truncated in the middle of
    >>>> a folder. The length of PATH is 1510 cahracters.
    >>>> Any other ideas?

    >
    >>> None. Sorry, I use neither XP nor the Task Scheduler (W2K
    >>> here). That is certainly odd. Perhaps your very-long-PATH can
    >>> and should be shortened considerably? Not that this is an

    > [ ]
    >
    >> Same result - only the first 1024 characters are echoed.
    >> Besides, I cannot shorten my PATH as I access my programs via
    >> the run menu, from the command prompt and batch files. Putting
    >> the respective paths in the PATH variable seems to suits these
    >> needs very well.

    >
    > Skiping everything else, how wedded are you to Windows Task
    > Scheduler? I don't use it at all and for several reasons.
    > Instead, I use nnCron Lite (free and a CKI Win32 clone of cron).
    > It you are insterested, I can test for any truncation with over-
    > long PATH values.
    >


    Could you do this? IF so, my PATH is 1052 charaters in length.
     
    Angel Tsankov, Feb 9, 2006
    #16
  17. Angel Tsankov

    Mark V Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:

    >>>>> Hello,
    >>>>>
    >>>>> I have a simple batch file that prints the PATH environment
    >>>>> variable: @echo off
    >>>>> echo %PATH%

    [ ]
    >> None. Sorry, I use neither XP nor the Task Scheduler (W2K
    >> here). That is certainly odd. Perhaps your very-long-PATH can
    >> and should be shortened considerably? Not that this is an
    >> explanation of course. Did you try echo/redirect %PATH% to a
    >> file?

    >
    > Same result - only the first 1024 characters are echoed.
    > Besides, I cannot shorten my PATH as I access my programs via
    > the run menu, from the command prompt and batch files. Putting
    > the respective paths in the PATH variable seems to suits these
    > needs very well.


    1510 characters in a PATH is (pardon me) ridiculous. I can't even
    imagine how in practice that can be. There are many methods to
    reduce the number of FQ directoy paths needing to be in PATH. Even
    if one works from CMD a lot. For one, place all your batch or
    other CLI script files in one or two directories "not too deep"
    (eg c:\util C:\batch c:\scripts or similar). If an application has
    need of very long or multiple paths in PATH, then start it from a
    batch file instead and include the setting of those locations into
    a more restricted and focus PATH variable also set inside the batch
    file. It seems you may be misusing the PATH on your system
    especially when you consider that every PATH search needs to
    "walk" through all of them until a "hit" occurs.

    Example: (not start in col 2, it wrapped)
    @echo off
    SETLOCAL
    SET PATH=%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;Q:\someapplication
    \deepdir1\deepdir2\bin
    START "" "Q:\someapplication\deepdir1\deepdir2\bin\someapp.exe"
    EXIT

    Line 2 is optional
    A
    CD /d Q:\someapplication\deepdir1\deepdir2\bin
    START "" someapp.exe"
    may also be suffient.

    Also, Shortcuts that specify the Working Directory ("Start In") can
    be used in many cases.

    Not bashing you or your system and there is much I do not know, but
    you should IMHO consider the points and try to shorten your PATH
    even above and beyond the TaskScheduler issue.
     
    Mark V, Feb 9, 2006
    #17
  18. "Mark V" <> wrote in message
    news:...
    > In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:
    >
    >>>>>> Hello,
    >>>>>>
    >>>>>> I have a simple batch file that prints the PATH environment
    >>>>>> variable: @echo off
    >>>>>> echo %PATH%

    > [ ]
    >>> None. Sorry, I use neither XP nor the Task Scheduler (W2K
    >>> here). That is certainly odd. Perhaps your very-long-PATH can
    >>> and should be shortened considerably? Not that this is an
    >>> explanation of course. Did you try echo/redirect %PATH% to a
    >>> file?

    >>
    >> Same result - only the first 1024 characters are echoed.
    >> Besides, I cannot shorten my PATH as I access my programs via
    >> the run menu, from the command prompt and batch files. Putting
    >> the respective paths in the PATH variable seems to suits these
    >> needs very well.

    >
    > 1510 characters in a PATH is (pardon me) ridiculous. I can't even
    > imagine how in practice that can be. There are many methods to
    > reduce the number of FQ directoy paths needing to be in PATH. Even
    > if one works from CMD a lot. For one, place all your batch or
    > other CLI script files in one or two directories "not too deep"
    > (eg c:\util C:\batch c:\scripts or similar). If an application has
    > need of very long or multiple paths in PATH, then start it from a
    > batch file instead and include the setting of those locations into
    > a more restricted and focus PATH variable also set inside the batch
    > file. It seems you may be misusing the PATH on your system
    > especially when you consider that every PATH search needs to
    > "walk" through all of them until a "hit" occurs.
    >
    > Example: (not start in col 2, it wrapped)
    > @echo off
    > SETLOCAL
    > SET PATH=%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;Q:\someapplication
    > \deepdir1\deepdir2\bin
    > START "" "Q:\someapplication\deepdir1\deepdir2\bin\someapp.exe"
    > EXIT
    >
    > Line 2 is optional
    > A
    > CD /d Q:\someapplication\deepdir1\deepdir2\bin
    > START "" someapp.exe"
    > may also be suffient.
    >
    > Also, Shortcuts that specify the Working Directory ("Start In") can
    > be used in many cases.
    >
    > Not bashing you or your system and there is much I do not know, but
    > you should IMHO consider the points and try to shorten your PATH
    > even above and beyond the TaskScheduler issue.


    Hmm, good point and I'll definitely give a good deal of thought.
    Thanks a lot!
     
    Angel Tsankov, Feb 9, 2006
    #18
  19. Angel Tsankov

    Mark V Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:

    >
    > "Mark V" <> wrote in message
    > news:...
    >> In microsoft.public.win2000.cmdprompt.admin Angel Tsankov wrote:
    >>

    [ ........ ]
    >>
    >>> Same result - only the first 1024 characters are echoed.
    >>> Besides, I cannot shorten my PATH as I access my programs via
    >>> the run menu, from the command prompt and batch files. Putting
    >>> the respective paths in the PATH variable seems to suits these
    >>> needs very well.

    >>
    >> Skiping everything else, how wedded are you to Windows Task
    >> Scheduler? I don't use it at all and for several reasons.
    >> Instead, I use nnCron Lite (free and a CKI Win32 clone of cron).
    >> [...] I can test for any truncation with over- long PATH values.


    > Could you do this? IF so, my PATH is 1052 charaters in length.


    Fails! I mucked with it for a while. No go.

    (W2k) a single variable is limited to 1024 bytes.
    Since the effective PATH is constructed from several components
    such as the Machine and User PATH it apparently can exceed the
    limit on-the-fly. I am not sure what the mechanism is for the
    truncation or exactly where it occurs, but it seems probable you
    won't get around it without,
    Shorten the effective path to < 1024
    Break it up and store it in several variables

    This one just might catch some of the sharper posters around here
    and get a better and more complete explanation than I can provide.


    What is the real problem that needs solving? There may be other
    ways to approach it such as using REG.EXE to read the registry from
    inside your scheduled batch file.
     
    Mark V, Feb 9, 2006
    #19
  20. Angel Tsankov

    Gary Smith Guest

    In microsoft.public.win2000.cmdprompt.admin Angel Tsankov <-sofia.bg> wrote:
    > Well, how can the TS set a limit on the length of env vars? Does it
    > copy the env vars when it creates the task or does it rely on the env
    > inheritance in child processes.
    > In the latter case there should be no problem with the length of PATH,
    > right?


    TS may very well copy the evironment variables when creating a task,
    especially if it needs to manipulate them for some reason. If I were you,
    I'd seriously work on reducing the size of the path. I though mine was
    overblown when it passed 300 bytes.

    --
    Gary L. Smith
    Columbus, Ohio
     
    Gary Smith, Feb 10, 2006
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.