?
Solved

Getting NULL Output when passing text file to a console application as an Arg

Posted on 2009-04-06
5
Medium Priority
?
155 Views
Last Modified: 2012-05-06
I'm passing a text file name into a variable in a SP that will then forward that name and append it to a console application for processing. As far as I can see the code looks right but, I get a NULL Output when I EXEC the SP. My console application is in .NET Visual C#. Do I need to add an @ symbol or will the path info be parsed correctly?
Thanks for your help Experts.
Wally
USE [DMS]
GO
/****** Object:  StoredProcedure [dbo].[RunPingUtil]    Script Date: 04/06/2009 08:30:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
ALTER Procedure [dbo].[RunPingUtil]
AS
BEGIN
	SET NOCOUNT ON;
 
DECLARE @Workstations varchar(max)
SET @Workstations = '\\Crprchblgsrd\d$\ProofOfConcept\data.txt'
 
DECLARE @CommandLine sysname;
SET @CommandLine = '\\Crprchblgsrd\d$\ProofOfConcept\ProofOfConcept.exe ' + @Workstations + '';
 
EXEC xp_cmdshell @CommandLine;
 
END

Open in new window

0
Comment
Question by:wally_davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 24079990
Well,not sure if I understood.There is no output parameter in your procedure without which you will not get an out put.I have added an output parameter and I am getting back the string
Alter Procedure [dbo].[RunPingUtil]
@myoutput varchar(4000)  output
AS
BEGIN
	SET NOCOUNT ON;
 
DECLARE @Workstations varchar(4000)
 
SET @Workstations = '\\Crprchblgsrd\d$\ProofOfConcept\data.txt'
 
DECLARE @CommandLine sysname;
SET @CommandLine = '\\Crprchblgsrd\d$\ProofOfConcept\ProofOfConcept.exe ' + @Workstations + '';
 
 --EXEC xp_cmdshell @CommandLine;
 select @myoutput=@CommandLine
END

Open in new window

0
 

Author Comment

by:wally_davis
ID: 24080298
ok, well, by verification of the output, -->
\\Crprchmsqdve\d$\ProofOfConcept\ProofOfConcept.exe data.txt
I would have thought the ProofOfConcept would have processed the data inside the txt file but it in fact has not when I want to check table on the database. I made sure that the data I entered into the text file had \r\n Escape sequences replaced in such a way that the workstation names were processed correctly. So, I still can't understand why, if the SP passes the filename to the executable correctly it should work. Any ideas why it isn't being processed?
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24082199
I assume you want to pass some information to the executable via command line.But what are you trying to achieve.First of all you are trying to execute a exe in a shared path which will lead to lot of security issues.
What exactly are you trying to do?
0
 

Accepted Solution

by:
wally_davis earned 0 total points
ID: 24082651
I had to copy the files (Exe and data.txt files) over locally to SQL Box, changed UNC to local D:\ in the SP and it work perfect.
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24082948
Thats exactly I am saying,Unless you map the path you might not be able to execute the exe with UNC it will not work.So I thought I should get points for this.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question