使用带有UNC路径的push和popd命令 [英] Use of pushd and popd command with UNC path

查看:114
本文介绍了使用带有UNC路径的push和popd命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下批处理文件以在 SQL 中运行存储的程序包,但出现了 UNC路径不受支持错误.如果我在服务器上运行它,它将正确运行.如果我与其他用户共享,则不会.我不想创建地图驱动器.我一直在阅读有关 pushd 命令的信息,它可能是一个选项,但不确定其工作原理.有人可以引导我吗?

 "\\ Server \ c $ \ Program Files(x86)\ Microsoft SQL Server \ 120 \ DTS \ Binn \ DTExec.exe"/f"\\ Sever \ c $ \ Packages \ Unapplied和Patient余额.dtsx" 

解决方案

如果愿意,可以使用 pushd 作为 net use 的快速版本.
如您所见,不支持UNC路径,因此您必须变通解决.命令 pushd \\ Server \ Path \ 将在运行它的计算机上创建一个网络驱动器,例如 Z:\ ,并自动切换到该驱动器(例如 cd/d Z:\ ),然后将路径压入堆栈(稍后再介绍).

然后您可以使用它来访问服务器目录:

 按下%〜dp0"推送\\ Server \ c $程序文件(x86)\ Microsoft SQL Server \ 120 \ DTS \ Binn \ DTExec.exe"/f"Packages \ Unapplied和Patient Balances.dtsx"弹出 

应该做到这一点.

popd 命令用于
1)删除网络驱动器,然后
2)从路径中弹出目录

因此,您实际上可以首先推送所需的所有服务器路径(根据文件系统,最多可达20个),然后在循环中为每个路径执行相同的操作,然后执行popd转到下一个存储的路径./p>

popd 之前添加 pause 并浏览浏览器时,您可以看到驱动器已连接.

注意::仅当至少一个驱动器号仍未使用时才有效,因为临时映射需要它!

添加了 pushd%〜dp0" 以消除注释中提到的警告.%dp0 代表第 0 个批处理文件参数的 d riv和 p ath,该参数始终是批处理文件本身.删除潜在的引号.

Edit2 :我启动了Windows 7 VM来对其进行单独测试.我写了一个.exe文件,它的唯一目的是执行一个批处理文件,该批处理文件将仅在当前时间在桌面上创建一个文件.我没有服务器,因此无法将其测试到100%,但是当尝试使用 pushd \\ localhost \ c $ 从VM运行它时,它工作正常……我试图从以下位置建立连接主机,但无法使其正常工作.您是否尝试过仅运行在服务器上创建的批处理文件?像这样:

 %time%>%USERPROFILE%\ Desktop \ myFile.txt" 

只是测试连接吗?

请随时询问是否不清楚!

I am running the following batch file to run a stored package in SQL and I am getting a UNC Paths are not supported error. If I run it on the server it runs correctly. If I share it with other users it does not. I do not want to create a map drive. I've been reading about pushd command and it may be an option, but not sure how it works. Can someone guide me?

"\\Server\c$\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\DTExec.exe" /f "\\Sever\c$\Packages\Unapplied and Patient Balances.dtsx"

解决方案

You can use pushd as a quick version of net use if you will.
As you already observed UNC paths are not supported and so you have to work around. The command pushd \\Server\Path\ will create a network drive on the machine it is running on like Z:\ , automatically switch to it (like cd /d Z:\) and pushing the path on a stack (relevant for later).

You can then use this to access the server directories:

pushd "%~dp0"
pushd \\Server\c$
"Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\DTExec.exe" /f "Packages\Unapplied and Patient Balances.dtsx"
popd

Should do the trick.

The command popd is used to
1) delete the network drive and
2) pop the directory from the path

So you could actually could first push all the server paths you need (up to ~20 based on your file system) and in a loop execute the same thing for each path and execute popd to go to the next stored path.

When adding a pause before the popd and looking into the explorer, you can see the drive connected.

NOTE: This will only work if at least one drive letter is still unused as it is needed for temporary mapping!

Edit: Added pushd "%~dp0" to get rid of a warning mentioned in the comments. %dp0 stands for the drive and path of the 0th batch-file argument that is always the batch-file itself. The ~ removes potential surrounding quotes.

Edit2: I started my Windows 7 VM to test this on my own. I wrote an .exe-file that only purpose it is to execute a batch-file that simply will create a file on the Desktop with the current time. I have no server so I could not test it to 100% but when trying to run it from the VM using pushd \\localhost\c$ it worked fine... I tried to establish a connection from the host machine, but could not get it to work that way nor the other. Have you tried just running a batch-file that you create on the server? Something like:

%time%>"%USERPROFILE%\Desktop\myFile.txt"

Just to test the connection?

Feel free to ask if something is not clear!

这篇关于使用带有UNC路径的push和popd命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆