15,891,976 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by HelpMewithCode (Top 46 by date)
HelpMewithCode
27-Feb-23 9:47am
View
Thank you
HelpMewithCode
17-Feb-23 9:20am
View
Above code run diskpart in admin mode only
i am getting disknumber also and volume also
but i am not able to separate the word called R
HelpMewithCode
3-Feb-23 6:52am
View
Original but atleast you can get me idea right
How to integrated windows diskpart with Python
HelpMewithCode
2-Feb-23 8:44am
View
above script dont have any problem but i want to assign disk letter
I need same kind of code
https://github.com/Duoquote/python-diskpart/blob/master/main.py
when i try fetch list disk command i was getting error like "int cant split "
template = result.split("\n")[0] #line 57
please can you help me how to ressolve this
thank you
HelpMewithCode
2-Feb-23 7:25am
View
Thank you so much
HelpMewithCode
2-Nov-22 1:47am
View
Can you help me out this ?
HelpMewithCode
1-Nov-22 11:40am
View
'https//pexels-photo-305821.jpeg', instead of jpeg , i need to run .py file at time
Example:
C:/user/demo.py file
C:/user/demo2.py file
HelpMewithCode
14-Sep-22 1:41am
View
But i am working with pipe So Can possible it possible to give just Pseudo code
C# client(Multiple) And python one server
HelpMewithCode
12-Sep-22 5:38am
View
Its possible in python side also?
HelpMewithCode
6-Sep-22 1:10am
View
Thank you
HelpMewithCode
29-Aug-22 3:27am
View
Deleted
Problem is I want Print Exception and Write into WriteFile
HelpMewithCode
25-Aug-22 8:21am
View
Yeh Thank you
HelpMewithCode
18-Aug-22 5:13am
View
You have given thats worked fine with one command .If its multiple command den its wont work
so tried to used file concept ..write to the file and read again
if write above code about file concept , its just write the txt file , but how do i read from the file
HelpMewithCode
18-Aug-22 4:31am
View
Deleted
I am able to to write the log in "output.txt"
now i want to read from "output.txt" and print to python console
HelpMewithCode
18-Aug-22 2:50am
View
Deleted
Richard MacCutchan could you help me on above code?
HelpMewithCode
18-Aug-22 0:37am
View
Deleted
import sys
# Save the current stdout so that we can revert sys.stdou after we complete
# our redirection
command1topython = "a = 5; print(\"Expected a = 4. Actual a = {} \".format(a))"
stdout_fileno = sys.stdout
# Redirect sys.stdout to the file
sys.stdout = open('output.txt', 'w')
exec(command1topython)
sys.stdout.close()
# Restore sys.stdout to our old saved file handler
sys.stdout = stdout_fileno
I able save in text file but how to I rediect sys.stdout in python console?
HelpMewithCode
17-Aug-22 8:19am
View
Deleted
I got Richard MachCutchan
but if run below code also i will get same error
>>> import subprocess
>>> s = subprocess.check_output(["echo", "Hello World!"])
>>>print(s)
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
What should be issue ?
HelpMewithCode
17-Aug-22 7:27am
View
Deleted
I am trying to executed this code
import subprocess
p1=subprocess.run('ls -la',shell =True)
print(p1.stdout)
File "C:\ram\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
I appreciate your support guys, thank you in advance.
HelpMewithCode
16-Aug-22 9:45am
View
Deleted
proc = subprocess.Popen(['ls -l'],Path.home(),text=True ,stdout=subprocess.PIPE)
File "C:\Test\lib\subprocess.py", line 753, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
Same Error i am facing
HelpMewithCode
16-Aug-22 9:06am
View
This is not what I except OriginalGriff
I have updated my code
please Can you look into this
HelpMewithCode
12-Aug-22 5:58am
View
just simple question if didn't understand
resp= (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
its posible in python remove 0,b from tuple so i can get my output like this
("a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))")
if possible help with method
HelpMewithCode
12-Aug-22 4:45am
View
Deleted
Richard MacCutchan
i am sending this command to python
var command1topython = "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
sw.WriteLine(command1topython);
.py file
resp = win32file.ReadFile(pipe_handle, 64*1024)
print(resp) #what i read data here (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
exec(resp) while exec the method i am geting error like, exec() arg 1 must be a string, bytes or code object
so what i am sending command i need to read same
my expected readData in python : "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
but what i am geting is : (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
so if you do python side
resp= (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
exec(resp)
you will get error like exec() arg 1 must be a string, bytes or code object
how do solve this issue
HelpMewithCode
12-Aug-22 2:15am
View
C# side
var command1topython = "a = 4; str(\"Expected a = 4. Actual a = {} \".format(a))";
sw.WriteLine(command1topython);
#python received
resp = win32file.ReadFile(pipe_handle, 64*1024)
print(resp)
resp output in python = (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
its adding extra value 0, b how i get exact value
HelpMewithCode
12-Aug-22 0:56am
View
Thank you so much CySalazar.
i need to pass argument through python script
my script.py
import sys
def prod(args):
if (len(args) == 0):
return 0
product = 1
for arg in args:
product *= arg
return product
if __name__ == "__main__":
if (len(sys.argv) < 2):
print(f"USAGE: {sys.argv[0]} cmd [args]")
sys.exit(1)
cmd = sys.argv[1]
args= (int(sys.argv[2]),int(sys.argv[3])) if (len(sys.argv) > 2) else []
if cmd == "sum":
print(sum(args))
elif cmd == "prod":
print(prod(args))
else:
print("cmd can be sum or prod.")
sys.exit(1)
program.cs
Console.WriteLine("Expected result = 6. Actual result = " + xrayprocess.RunScript("\"C:\\script.py\" prod 2 3"));
//Console.ReadLine();
//Execute 2 python commands consecutively
var pythonCommand1 = "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
var pythonCommand2 = "b=2;print(\"Expected b = 2. Actual b = {} \".format(b));print(\"Expected a = 4. Actual a = \");print(a)";
Console.WriteLine(xrayprocess.ExecuteCommand(pythonCommand1));
Console.WriteLine(xrayprocess.ExecuteCommand(pythonCommand2));
}
RunScript.py
public string RunScript(string script)
{
try
{
if (!_pythonProcess.HasExited)
{
_pythonProcess.Kill();
}
_pythonProcess.StartInfo.Arguments = string.Format("{0}", script);
_pythonProcess.Start();
var outputString = _pythonProcess.StandardOutput.ReadToEnd();
return outputString;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
return null;
}
}
with above the code i want to run multiple command with one processs
Exact same output which mentioned but using above script
@CySalazar i hope u will help me on this
HelpMewithCode
9-Aug-22 5:25am
View
thank you
HelpMewithCode
9-Aug-22 1:32am
View
its possible to Call python method from c# using Above code
HelpMewithCode
8-Aug-22 8:14am
View
No need Thank you its working fine
Thanks Richard MacCutchan
I need one more Its possible to python method using Pipes from c# and execute them
I dont so asked you , if possible please let me know how i will do
HelpMewithCode
8-Aug-22 6:50am
View
oky I have remove the Time.sleep
but i tried with forloop that i can atleast read and write 5 times
but its only printing once time
HelpMewithCode
8-Aug-22 6:19am
View
Thanks Richard MacCutchan
Its work to get Data to the c# console .
But i need to update read and write within 2 sec
How it will work
both the side i have given while loop and time frame 2 sec
Anything need to changed ?
HelpMewithCode
4-Aug-22 11:55am
View
Leave Richard McCutchen your just argumenting nothing your doing wasting my time
I already I have mentioned everything.
What i am looking for ?
Thank you
HelpMewithCode
4-Aug-22 8:54am
View
Problem is .. I want to send some command to python through c# and through the python return to the c# console
Thats what i lookingfor
HelpMewithCode
4-Aug-22 8:32am
View
https://www.codeproject.com/Questions/165990/Starting-cmd-exe-in-console-application-in-differe
Same way above the link but c# as client and python with server
Above code need to be combined
@Robert Rohde you have already explain with c# two way communications with PIPEs
Could please apply here same c# and python code
HelpMewithCode
4-Aug-22 6:43am
View
Problem is i have tow python code and 2 c# code which i need to combine
At last i need python console :
Hello from c#
And c# console
Hello from python
I need above should how should i combined
HelpMewithCode
4-Aug-22 1:54am
View
Hi can help me out with my code
HelpMewithCode
3-Aug-22 9:53am
View
@Richard MacCutchan I got above code are working with deferent solution exactly what you have mentioned
But i want to combine above the code and get the result
Please just help me out the combine the code
I taging everybody who can help combine the code
@Patrice T
@OriginalGriff
@Gerry Schmitz
@Sampath579
HelpMewithCode
1-Aug-22 10:50am
View
Console.WriteLine("Expected result = 6. Actual result = " + testProcess.RunScript("\"C:main\\test\\Test.py\" pro 2 3"));
Console.ReadLine()
I have tried what you have mentioned but it will run one process at a time ..
could you help me out this please
HelpMewithCode
13-Jul-22 1:55am
View
Hi Richard Need help
HelpMewithCode
12-Jul-22 8:50am
View
I am sorry Richard and Griff but i need help from you.
Other way Its that possible parser the binary data in (Newtonsoft.Json[^] and System.Text.Json[^]
Below example:
my.json file
{
"interface": "bisr_1",
"start_addr": 0,
"data": "999p1r1p",
"path": "D:\\my\\path\\to\\text_output.txt"
}
Value of "Path" which contains Binary data in txt , Now question how to parse that and get data .
Its That possible in above library file , if possible just let me know .
My code Using lib to parse the Value of binary data .
static void Main(string[] args)
{
string jsonFilePath = @"System.json";
string json = File.ReadAllText(jsonFilePath);
Dictionary<string, object=""> json_Dictionary = JsonConvert.DeserializeObject<dictionary<string, object="">>(json);
JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
if (reader.Value != null)
{
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
}
else
{
Console.WriteLine("Token: {0}", reader.TokenType);
}
}
Token: StartObject
Token: PropertyName, Value: interface
Token: String, Value: bisr_1
Token: PropertyName, Value: start_addr
Token: Integer, Value: 0
Token: PropertyName, Value: data
Token: String, Value: 999p1r1p
Token: PropertyName, Value: path
Token: String, Value: D:\my\path\to\text_output.txt
Token: EndObject
Stored Json Data
Press any key to continue . . .
Now Value: D:\my\path\to\text_output.txt which stored binary data . Now how to read that binary data
If u guys help me on this I wont Irritated you
@originalGriff@patriceT @Richard @Cpallini
Thanks in advanced
HelpMewithCode
12-Jul-22 5:14am
View
static void Main(string[] args)
{
//Dictionary<string, object=""> data = new Dictionary<string, object="">();
string jsonFilePath = @"C:\Test2\JosonParser - Copy\JosonParser\N6X1345.json";
string json = File.ReadAllText(jsonFilePath);
Console.WriteLine(json);
}
#Above which i trying i am just printing Json file ,now i want to read each key and Value from the Json.
This i need help
HelpMewithCode
12-Jul-22 4:49am
View
Its my Client requirement.
It should be own lib .
So just help me out on this how to parser json in Simple C# programs
{
"fuse_image_metadata": {
"schema_version": 2,
"product_name": "product_X",
"owner": "xyz",
"ecid": "N6X1345_01_x-1_y3",
"2d_barcode": "xxx",
"jtag_id": "xxx",
"last_modified_timestamp": "2021-09-07 11:01:00",
"rule_revision": "0",
"sku_collateral_version": "1.0",
"dff_file": "N6X1345_01_x-1_y3_FT1_20210831_140128_ENG.json",
"fid_image_file": "fid_image_r1.0.json",
"image_builder_name": "fusebuild.py",
"image_builder_version": "0.0"
},
"sku_fuse_data": {
"1.A.PROD": {
"fid_definition": {
"sku_id": "1.TEST.DS0",
"sku_number": "1",
"security_state": "PROD",
"quality_milestone": "DS0",
"num_enabled_cores": "124",
"ate_tp_rev": "0",
"fuse_recipe_rev": "0",
"vf_curve_rev": "0",
"array_rwa_rev": "0",
"thermal_sensor_trim": "static_presi",
"core_disable": "static",
"core_vf_curve": "static_safe_presi",
"other_vf_curve": "static_safe_presi",
"ldo_trim": "static_presi"
},
"ate_sys_fuse_data": {
"format": "binary",
"controller_type": "MSFT_FMC",
"addr_data_map": {
"0": {
"interface": "box_0",
"start_addr": 0,
"data": "00000000000000000000000000000001"
},
"32": {
"interface": "box_0",
"start_addr": 32,
"data": "11110000000000000000000000000000"
}
}
},
"ate_bisr_fuse_data": {
"mock_bisr_0": {
"format": "rle",
"controller_type": "BISR",
"addr_data_map": {
"0": {
"interface": "bisr_0",
"start_addr": 0,
"data": "100p2r150p3r50p"
}
}
},
"mock_bisr_1": {
"format": "rle",
"controller_type": "BISR",
"addr_data_map": {
"0": {
"interface": "bisr_1",
"start_addr": 0,
"data": "999p1r1p"
}
}
}
},
"sfo_fuse_data": {
"system_gsram": {
"format": "binary",
"addr_data_list": [
{
"interface": "gsram_0",
"start_addr": 0,
"data": "1111000000000001"
}
]
},
"mock_bisr_0": {
"format": "rle",
"addr_data_list": [
{
"interface": "bisr_0",
"start_addr": 0,
"data": "100p2r150p3r50p"
}
]
},
"mock_bisr_1": {
"format": "rle",
"addr_data_list": [
{
"interface": "bisr_1",
"start_addr": 0,
"data": "999p1r1p"
}
]
}
}
}
}
}
//above mine Json file I want to parse with c# prog
HelpMewithCode
12-Jul-22 2:45am
View
My requirement has Changed , i am not using any Newtonsoft lib even others which u mentioned in article .
Normal c# programs without using any library Parse the Json file .
Could you help Grame_grant i am stuck
HelpMewithCode
11-Jul-22 12:55pm
View
Great Article, I should any not used any library file .
Without using any library how to parse the Json file .
If you have written any article , you help me out
HelpMewithCode
11-Jul-22 6:59am
View
Hi Original Griff , It possible to automated the with c# .
I mean to say Once load the JSON file it should automatically generate the Class .
If have any idea let me know
HelpMewithCode
5-Jul-22 2:20am
View
Do you any example Richard McCutchen?
Which i can start my project
please help
HelpMewithCode
4-Jul-22 11:12am
View
Yes Exactly I thought to do socket communication between c# and python interpreter and send the command through the c# which will be executed in python interpreter n return .
Richard McCutchen have you work on any project concept of same .
How do I connect c# and python interpreter via sockets ?
Could you guide me
if possible i will connect you personally .
HelpMewithCode
4-Jul-22 7:43am
View
Hi Rechard MacCutchan thank you for the reply ,
Just forgot about above line its just feature .
My general questions is i have test program in c# , i need to send the command through C# to python and run into the python interpreter , So how do i implement this?If you could help it will great full
Show More